How can i read the info on a mysql table and then put it the data into a html table?
This uses PEAR, but is there away to do without it?
PHP Code:<html>
<body>
<?php
// establish a dsn string (this should actually be done in a header file)
$dsn = array('phptype' => 'mysql', 'hostspec' => 'localhost', 'database' => 'tommy', 'username' => 'table',
'password' => '');
$db = DB::connect( $dsn);
$rsUser = $db->query("SELECT Name, Type, Date/Time, Format, Version FROM table");
$table = new HTML_Table (Array ("border" => "1", "width" => "50%", "align" => "center"));
$table->addRow(Array("Name", "Type", "Format", "Version", "Download", "Download Compressed File"), "",
"TH");
while ($rsUser->fetchInto($rowUser, DB_FETCHMODE_ASSOC)) {
extract ($rowUser);
$rowUser["Name"] = "<A HREF = 'viewprofile.php?user=$username'>$username</A>";
$rowUser["Download"] = "<A HREF = '$username&/$type/&$date/'>Download</A>";
$rowUser["Download Compressed File"] = "<A HREF =
'compress.php?$username&$type&$date'>Zip file</A>"
$rowUserProcessed = Array();
foreach ($rowUser as $field) $rowUserProcessed[] = $field;
// add the row to the HTML table
$table->addRow($rowUserProcessed);
}
$db->disconnect();
$table->altRowAttributes (1, "style = 'background-color: #CCCCCC'", "style = 'background-color:
#EEEEEE'");
$table->setRowAttributes (0, "style = 'background-color: #000000; color: #FFFFFF'");
$table->display();
?>
</body>
</html>





Reply With Quote
