Link to home
Start Free TrialLog in
Avatar of sam928
sam928

asked on

mySQL 'SHOW TABLES' << HOW TO show the tables in DESCENDING order.

hello, i have a simple PHP script that displays all of the tables in the mySQL database.

By default it loads the tables in ASC order (a-z, 1-9)    ((with the script i have below in the snippet))

QUESTIONS .. how do i make it load the tables in DESCENDING order?

I tried this below.. but it did not work....

$sqlString = "SHOW TABLES order By DSC";

does anybody know how to do this?


//WORKING VERSION THAT LOADS THE TABLES IN ASCENDING ORDER BY DEFAULT
$sqlString = "SHOW TABLES";
 
$result = mysql_query($sqlString) ;
 
$cant = 0;
while ($tables = mysql_fetch_array($result)) {
	
     //printf("album$cant= %s %s",urlencode($tables[0]),"&");
	 printf("albumName%s=%s&", $cant, urlencode($tables[0]));
	 $cant++;
}
echo "cant=$cant";
?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I think you would have to sort an array of table names to get this in descending order.  I'll try it.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked for me.  You can probably adapt it pretty easily.  Best, ~Ray
Sorry Mr Paseur, I've not refreshed the page before posting.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The mysql way:

select table_name from information_schema.tables where table_schema=database() order by table_name desc;