Source of: /ADI/displayTable_mysql/filmes4.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>base de dados de filmes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
include 'inc/db.inc';
function displayTable($db, $title, $query)
{
if(!($result = @ mysql_query($query,$db )))
showerror();
$ncols = mysql_num_fields($result);
$nrows = mysql_num_rows($result);
if( $nrows > 0 ) {
printf("<h2>$title</h2>\n");
printf("<table border=2>\n");
printf("<tr>\n");
for($j=0; $j<$ncols; $j++) {
$column_name = mysql_field_name($result, $j);
printf("<th align=left>$column_name</th>\n");
}
printf("</tr>\n\n");
for($i=0; $i<$nrows; $i++) {
$tuple = mysql_fetch_array($result,MYSQL_NUM);
printf("<tr>\n");
for($j=0; $j<$ncols; $j++)
printf("<td>%s</td>\n", $tuple[$j] );
printf("</tr>\n\n");
} printf("</table>\n");
} }
$db = dbconnect($hostname,$db_name,$db_user,$db_passwd);
if($db) {
$title = "Tabela de filmes";
$query = "SELECT * FROM filmes";
displayTable($db, $title, $query);
$title = "Tabela de actores";
$query = "SELECT * FROM actores";
displayTable($db, $title, $query);
mysql_close($db);
}
?>
</body>
</html>