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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.