Jump to content

SHOW TABLES Query Help


Tudhope

Recommended Posts

I want to get a list of all tables in a database, at the moment im using\"

$tables = mysql_query(\"SHOW TABLES FROM games\");

 

\'games\' being the database name. This ok but its sent back unorded. I get r1, r11, r12, r13, r14 ..... r19, r2, r20, r21, r22. The name of the tables are r1 through to r22. So I tried out:

$tables = mysql_query(\"SHOW TABLES FROM games SORT BY Asc\");

but this doesnt work. How can i order what is return so that i get, r1 r2 r3 r4 r5.......? Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/1504-show-tables-query-help/
Share on other sites

Then this might solve it:


<?php

  $dbname = \'db_name\';



  if (!mysql_connect(\'localhost\', \'user\', \'password\')) 

 {

       print \'Could not connect to mysql\';

       exit;

  }



mysql_select_db("$dbname");

$query = "show tables";

$result = mysql_query($query);

$num_results = mysql_num_rows($result);

print "There are $num_results tables.<br>";

for ($i = 0; $i < $num_results; $i++)

 {

 	$row = mysql_fetch_array($result);

 	print "table: " . $row[0] . "<br>";

 }

?> 

Link to comment
https://forums.phpfreaks.com/topic/1504-show-tables-query-help/#findComment-4951
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.