PHP-Tutorial -> competition/index.php
<?php define( "SELECT_LIST", "SELECT name,email,bear FROM competition" ); define( "TMPL_PATH", "../templates" ); define( "TMPL_FILE", "showlist.tmpl" ); define( "HOST", "localhost" ); define( "USER", "<USERNAME>" ); define( "PASSWD", "<PASSWORD>" ); define( "DB", "<DATABASENAME>" ); /* Home: http://pear.php.net/package/HTML_Template_IT */ require_once "HTML/Template/IT.php"; // Init $con = dbx_connect( DBX_MYSQL, HOST, DB, USER, PASSWD ) or die( "<html><body>Error connecting to database!</body></html>" ); $template = new HTML_Template_IT( TMPL_PATH ); $template->loadTemplatefile( TMPL_FILE, true, true ); // Data processing $result = dbx_query( $con, SELECT_LIST ); if ( is_object($result) ) { if ( $result->rows > 0 ) { for ( $i=0; $i < $result->rows; $i++ ) { $template->setCurrentBlock( "participant" ); $template->setVariable( $result->data[$i] ); $template->parseCurrentBlock( "participant" ); } } else { $template->setCurrentBlock( "participant" ); $template->setVariable( "name", "" ); $template->setVariable( "email", "" ); $template->setVariable( "bear", "" ); $template->parseCurrentBlock( "participant" ); } } dbx_close( $con ); // Create HTML output header('Content-Type: text/html; charset=utf-8'); $template->show(); ?>