Deanznet Posted August 11, 2009 Share Posted August 11, 2009 Okay im trying to get a list of mysql tables from a database to get listed into a html table. Im trying to get a 2 column table like below. Table Names - Link Table 1 Click Me link (la.com/ss.php?table=table1) Table 2 Click Me link (la.com/ss.php?table=table2) Table 3 Click Me link (la.com/ss.php?table=table3) Someone help me do that please! This is what i got but it doesn't work. $sql = "SHOW TABLES FROM $db_name"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } $table = 0; while ($table < mysql_num_rows($result)) { echo "<tr>\n"; echo "<td>\n"; echo "{$row[0]}\n"; echo "</td>\n"; echo "</tr>\n"; } mysql_free_result($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169779-listing-mysql-results-in-a-table/ Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 Try this, obviously i haven't tested it :-) $sql = "SHOW TABLES FROM $db_name"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo "<table>"; while ($row= mysql_fetch_array($result)) { echo "<tr>"; echo "<td>{$row['COLUMN_NAME FROM DATABASE']}</td>"; echo "</tr>"; } echo "</table>"; mysql_free_result($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169779-listing-mysql-results-in-a-table/#findComment-895694 Share on other sites More sharing options...
waterssaz Posted August 11, 2009 Share Posted August 11, 2009 sorry didn't read properly waht you are trying to do. have changed above code slightly to this: $sql = "SHOW TABLES FROM $db_name"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } echo "<table>"; while ($row= mysql_fetch_row($result)) { echo "<tr>"; echo "<td>{$row[0]}</td>"; echo "</tr>"; } echo "</table>"; mysql_free_result($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169779-listing-mysql-results-in-a-table/#findComment-895712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.