christianix.de

-> Main -> 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_connectDBX_MYSQLHOSTDBUSERPASSWD ) or
       die( 
"<html><body>Error connecting to database!</body></html>" );
$template = new HTML_Template_ITTMPL_PATH );
$template->loadTemplatefileTMPL_FILEtruetrue );

// Data processing
$result dbx_query$conSELECT_LIST );
if ( 
is_object($result) ) {
    if ( 
$result->rows ) {
        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();
?>
Verantwortlich/Responsible: Martin Christian (martin at christianix dot de)