struggling with rsort

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    struggling with rsort

    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?



    Here's my code:

    <?
    $order_list_que ry = mysql_query("sh ow tables like 'order_%'");
    while ($order_list_ar ray = mysql_fetch_arr ay($order_list_ query)){
    rsort($order_li st_array);
    echo $order_list_arr ay[0] . "<br>";
    }
    ?>

    generates:

    order_06-03-2006-001
    order_06-03-2006-002
    order_06-04-2006-001
    order_06-05-2006-001
    order_06-05-2006-002
    order_06-05-2006-003
    order_06-05-2006-004

  • Rik

    #2
    Re: struggling with rsort

    Dave wrote:[color=blue]
    > 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_que ry = mysql_query("sh ow tables like 'order_%'");
    > while ($order_list_ar ray = mysql_fetch_arr ay($order_list_ query)){
    > rsort($order_li st_array);
    > echo $order_list_arr ay[0] . "<br>";
    > }[/color]

    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_ar ray = mysql_fetch_arr ay($order_list_ query)){
    $list[] = $order_list_arr ay[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


    Comment

    • Dave

      #3
      Re: struggling with rsort

      Rik wrote:[color=blue]
      > You COULD:
      > $list = array();
      > while ($order_list_ar ray = mysql_fetch_arr ay($order_list_ query)){
      > $list[] = $order_list_arr ay[0];
      > }
      > rsort($list);
      > foreach($list as $order){
      > echo $order.'<br />';
      > }[/color]

      This did the trick! Thanks a million!

      Comment

      Working...