Printing table(from mysql) name in a php page
Hi,
I need to print the names of the tables existing in a database,on my php page. For example if in the database QUIZ I have tables:
- Questions
- Answers
- Students
..I want to print on a php page:
Questions
Answers
Students
I selected the database properly and I tried with:
$rez0=mysql_query("show tables");
$nrez0=mysql_num_rows($rez0);
for($k=0;$k<$nrez0;$k++) {
$table=mysql_fetch_object($rez0);
echo "Tables: ".$table->name."<br>";
}
...but it just prints "Tables" a number of times..I assume "name" is not ok..Than what is ok? Or is there another way to do this? I would appreciate the help..
Diana Bodnarescu
2008-05-03 20:55:12
Re:
Ok,I figured it out :P For anyone else who deals with this problem,the solution is:
$rez0=mysql_query("show tables");
$nrez0=mysql_num_rows($rez0);
for($k=0;$k<$nrez0;$k++) {
$table=mysql_fetch_row($rez0);
echo "Table: ".$table[0]."<br>";
}
Have a great day everyone! :)
Veselin
2008-05-04 09:59:51
Re:
thanks for sharing this with us Diana. By the way you can have it like this
$rez0=mysql_query("show tables");
$nrez0=mysql_num_rows($rez0);
while ($table=mysql_fetch_row($rez0)) {
echo "Table: ".$table[0]."<br>";
}