Source of: /ADI/displayTable_mysql/filmes5.php
<?php
require_once "HTML/Template/IT.php";
include 'inc/db.inc';
function displayTable($db, $title, $query)
{
$template = new HTML_Template_IT('.');
$template->loadTemplatefile('filmes5_templateIT.html', true, true);
if(!($result = @ mysql_query($query,$db )))
showerror();
$ncols = mysql_num_fields($result);
$nrows = mysql_num_rows($result);
if( $nrows > 0 ) {
$template->setVariable('TITULO', $title);
$template->parse("TITLE");
$template->setCurrentBlock("HEADER");
for($j=0; $j<$ncols; $j++) {
$column_name = mysql_field_name($result, $j);
$template->setVariable('VALUE1', $column_name);
$template->parseCurrentBlock();
}
for($i=0; $i<$nrows; $i++) {
$tuple = mysql_fetch_array($result,MYSQL_NUM);
$template->setCurrentBlock("COL");
for($j=0; $j<$ncols; $j++) {
$template->setVariable('VALUE', $tuple[$j]);
$template->parseCurrentBlock();
}
$template->parse("ROW");
} $template->show();
} }
$db = dbconnect($hostname,$db_name,$db_user,$db_passwd);
if($db) {
$tables = array( array("Filmes anteriores a 1970", "SELECT * FROM filmes WHERE ano<1970"),
array("Actores", "SELECT * FROM actores"),
array("Estúdios", "SELECT * FROM estudios"),
array("Realizadores", "SELECT * FROM realizadores"),
array("Participa", "SELECT * FROM participa"));
for($i=0; $i<count($tables); $i++) {
$title = $tables[$i][0];
$query = $tables[$i][1];
displayTable($db, $title, $query);
}
mysql_close($db);
}
?>