| 
	
 | 
 Posted by Rik on 06/19/05 11:49 
Dave wrote: 
> I'm trying to sort a list of mysql tables in reverse order.  The 
> problem is the array displays in the same order regardless of the 
> rsort addition. 
> 
> Can anyone see what I'm missing? 
> <? 
> $order_list_query = mysql_query("show tables like 'order_%'"); 
> while ($order_list_array = mysql_fetch_array($order_list_query)){ 
>         rsort($order_list_array); 
>         echo $order_list_array[0] . "<br>"; 
> } 
 
You're not sorting the total results, you are sorting every 'row' in the 
field by value, of which it has only one: 
 
print_r($order_list_array): 
gives: 
Array{ 
    [0] => 'order_06-03-2006-001' 
} 
 
You COULD: 
$list = array(); 
while ($order_list_array = mysql_fetch_array($order_list_query)){ 
      $list[] = $order_list_array[0]; 
} 
rsort($list); 
foreach($list as $order){ 
    echo $order.'<br />'; 
} 
 
Unfortunately, as far as I know, it's not possible to sort the tables in the 
query directly. 
 
I wonder what the use is to have a table per order though, any special 
reason? I don't know wether it's possible for you, but I'd consider using a 
different table structure, where orders a rows (perhaps with links to other 
tables). That would save a lot of fiddling about, and makes querying the 
database also a bit faster I'd believe. 
 
Grtz, 
--  
Rik Wasmus
 
  
Navigation:
[Reply to this message] 
 |