[SOLVED] listing Tables in data base

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

[SOLVED] listing Tables in data base

Post 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);
?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

do you mean in a table?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

See: http://www.php.net/mysql

Good examples there.
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

no i want to list the tables in the database not not the records in a table
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Maybe you should see that link I posted.
hward
Forum Contributor
Posts: 107
Joined: Mon Apr 19, 2004 6:19 pm

Post by hward »

that lists all the records in a table not the tables in a database though
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
User avatar
sakaveli
Forum Commoner
Posts: 60
Joined: Tue Apr 06, 2004 9:42 am

Post 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)
Post Reply