Source of: /ADI/displayTable_mysql/filmes1.php
<?php
require_once "HTML/Template/IT.php";
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
function dbconnect($hostname, $db_name,$db_user,$db_passwd)
{
$db = @ mysql_connect($hostname, $db_user,$db_passwd);
if(!$db) {
die("Nao consigo ligar ao servidor da base de dados.");
}
if(!(@ mysql_select_db($db_name,$db))){
showerror();
}
return $db;
}
function displayFilmes($result)
{
$template = new HTML_Template_IT('.');
$template->loadTemplatefile('filmes1_templateIT.html', true, true);
$nrows = mysql_num_rows($result);
if( $nrows > 0 ) {
for($i=0; $i<$nrows; $i++) {
$tuple = mysql_fetch_array($result,MYSQL_ASSOC);
$nome = $tuple['nome'];
$ano = $tuple['ano'];
$duracao = $tuple['duracao'];
$aCores = $tuple['acores'];
$nomeEstudio = $tuple['nomeestudio'];
$nomeRealizador = $tuple['nomerealizador'];
$template->setCurrentBlock("FILMES");
$template->setVariable('NOME', $nome);
$template->setVariable('ANO', $ano);
$template->setVariable('DURACAO', $duracao);
$template->setVariable('ACORES', $aCores);
$template->setVariable('NOMEESTUDIO', $nomeEstudio);
$template->setVariable('NOMEREALIZADOR', $nomeRealizador);
$template->parseCurrentBlock();
} $template->show();
} }
$db = dbconnect("localhost", "filmes","figo", "xxxxx");
if($db) {
$query = "SELECT * FROM filmes";
if(!($result = @ mysql_query($query,$db )))
showerror($db);
displayFilmes($result);
mysql_close($db);
}
?>