You are here: Re: struggling with rsort « PHP Programming Language « IT news, forums, messages
Re: struggling with rsort

Posted by Rik on 11/29/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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация