Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Order by problem

    I'm making a user gallery of items and i want to order it by name.

    The only problem is i'm getting the name of the item after i do the while.

    Like:

    $sel=mysql_query("SELECT * FROM `inventory`");
    while($row=mysql_fetch_array($sel)) {
    $itemid = $row['itemid'];
    $se=mysql_query("SELECT * FROM `items` WHERE `ID` = '$itemid'") or die(mysql_error());
    $f=mysql_fetch_array($se);
    $itemname = $f['itemname'];
    echo"$itemname<br>";
    }

    How would i get it to order by itemname?

  • #2
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    sort()

    For more info, give more info

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can sort your query results using the ORDER BY clause in the query, i.e.
    Code:
    SELECT * FROM items WHERE ID = '99999'
    ORDER BY itemname
    By the way, you can combine both of your queries into one using a join:
    Code:
    SELECT *
    FROM items
    JOIN inventory
    ON items.ID = inventory.itemid
    ORDER BY items.itemname
    Last edited by Fumigator; 08-30-2007 at 11:38 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •