Jump to content

[SOLVED] hm.. Print db in table with table header. (mostly html)


chris11

Recommended Posts

Im using a sortable script to sort the data from the database when printed out in a table.

The issue im having is that each row in my data base is getting it's own head like so..

 

Untitled.jpg

 

Course i would like only one head one table but still have the script.

 

What i did as an easy step be4 was make the table head on its own with another table under it with the DB table. This is an issue because it causes things to not line up right if names are to big etc. Also no JS this way.

 

// gets data
$query = "SELECT id, filename, description, filesize, date FROM uploads";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0){
   echo "Database is empty <br>";
}
else{
   while(list($id, $name, $description, $filesize, $date) = mysql_fetch_array($result)){
echo "<table id=\"test1\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"sortable-onload-5-6r rowstyle-alt colstyle-alt no-arrow\">\n";
echo "<caption>The db</caption>\n";
echo "<thead>\n";
echo "<tr>\n";
echo "<th class=\"sortable-numeric\">Name</th>\n";
echo "<th class=\"sortable-numeric\">Date</th>\n";
echo "<th class=\"sortable-numeric\">Size</th>\n";
echo "<th class=\"sortable-date-dmy\">Info</th>\n";
echo "\n";
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";

echo "<td><a href=\"download.php?id='.$id.'\">'.$name.'</a></td>\n";
echo "<td>$date</td>\n";
echo "<td>$filesize</td>\n";
echo "<td>$description</td>\n";

echo "</tbody>\n";
echo "\n";

   }
}
?>

 

Any help would be awesome. Thanks

Chris

this chunk should be before the while loop

echo "<table id=\"test1\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"sortable-onload-5-6r rowstyle-alt colstyle-alt no-arrow\">\n";
echo "<caption>The db</caption>\n";
echo "<thead>\n";
echo "<tr>\n";
echo "<th class=\"sortable-numeric\">Name</th>\n";
echo "<th class=\"sortable-numeric\">Date</th>\n";
echo "<th class=\"sortable-numeric\">Size</th>\n";
echo "<th class=\"sortable-date-dmy\">Info</th>\n";
echo "\n";
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";

 

edit:

 

and this should be after the while loop

echo "</tbody>\n";
echo "\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.