Wrote yfastud:
Correct me if I'm wrong, you talk about nested tables where table1's fields containing titles of all other tables, so the output of table1 will be other tables' titles and content are from other tables. BTW, I only stated 1 very simple example so you can get the idea, you might find some other way which might be more easy or more advanced ;-)
My reply: You are being a bit unkind, methinks...
I just want any old table at all to reflect the column titles and so far I have not figured out how to do that. If I include an array of titles, or column names, as row one, then with an integer value for any of these columns (like "age"
, an error report will inform me that it was expecting an integer on line one and the code will fail to execute.
But I have moved on (that problem can wait); I've run into a trickier problem. I have indeed learned how to create and populate tables and to print them to screen in a nice list (using PHP and MySQL by the way), but when I try to list them in a regular table form (in cells), what happens is that the list, which is alphabetical (a listing of countries with "region" and "population" as additional variables), ceases to execute in an orderly fashion (the list is in alphabetical order, remember) at some random point [maybe not so random, it always stops after "Nicaragua" and recommences at "Afhanistan", two countries that my homeland have had a lot of static with
], loops back to the beginning, then charges off again, but prints some "s"es, then some "m"s, some "n"s again, etc., it simply goes off the tracks, although it eventually does get to "Zimbabwe" after about 900 entries (there are 193 original entries). What the devil is wrong here?
Here is the code I use to print the table:
// Retrieve all the data from the "worldstats" table
$result = mysql_query("SELECT * FROM worldstats"
or die(mysql_error());
// store the record of the "worldstats" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry
// create query
$query = "SELECT * FROM worldstats";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another (note that the "rows" below refer in fact to columns)
echo "<table cellpadding=10 border=1>";
while($row = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
Thanks much,
Wimp_i_Wamp