Page 1 of 1

[SOLVED] listing Tables in data base

Posted: Fri Oct 22, 2004 2:45 am
by hward
i can get this to work and it prints out the tables just fine but i want to be able to use them in a display block and can't figure out how to do it.

Code: Select all

<?php
mysql_connect("localhost", "user", "password");
$result = mysql_list_tables("db_name");
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
    echo "Table: ", mysql_tablename($result, $i), "\n";
}

mysql_free_result($result);
?>

Posted: Fri Oct 22, 2004 3:55 am
by phpScott
do you mean in a table?

Posted: Fri Oct 22, 2004 4:29 am
by m3mn0n
See: http://www.php.net/mysql

Good examples there.

Posted: Fri Oct 22, 2004 10:19 am
by hward
no i want to list the tables in the database not not the records in a table

Posted: Fri Oct 22, 2004 10:55 am
by m3mn0n
Maybe you should see that link I posted.

Posted: Fri Oct 22, 2004 11:11 am
by hward
that lists all the records in a table not the tables in a database though

Posted: Fri Oct 22, 2004 2:38 pm
by kettle_drum
But the link on the page Sami provided you will link you to the mysql_list_tables() function. We are trying to help you to learn on these forums - not just give you complete answers. Help us help you by at least looking at links people post.

Posted: Fri Oct 22, 2004 5:21 pm
by sakaveli
well said kettle, i think im getting the hang of php and mysql after a whole year of posting my problems on this forum!

its a long journey but there is always light guiding you (in the form of a kettle)