#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    51
    Rep Power
    15
    I need to store the results row ids from
    a querry into an array.
    CODE:
    ----------------------------------

    function sort_cats() {
    global $db;
    $cnt = 1;
    $get_top = mysql_query("select CID, PID from CATS where PID='0' order by CAT asc",$db);
    while ($data = mysql_fetch_array($get_top)) {
    $sorted = array($cnt => $data[CID]);
    $cnt++;
    }

    return $sorted;
    }

    ------------------------------------------
    Something like this but that works.

    Thanks for any help.
    Charlie...
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Your problem lies in that you are reinitializing the array with each iteration of your loop. Change this:

    $sorted = array($cnt => $data[CID]);

    To:

    $sorted[$cnt]=$data[CID]);

Similar Threads

  1. MySQL query not getting array properly [PHP]
    By adz32 in forum MySQL Help
    Replies: 1
    Last Post: February 11th, 2004, 04:51 PM
  2. Replies: 2
    Last Post: January 14th, 2004, 06:07 PM
  3. Replies: 4
    Last Post: January 14th, 2004, 06:22 AM
  4. Overwriting mysql query with the query results
    By onerandomday in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 05:45 AM
  5. populate array with mysql data
    By clearbar in forum PHP Development
    Replies: 2
    Last Post: January 14th, 2004, 04:41 AM

IMN logo majestic logo threadwatch logo seochat tools logo