...

View Full Version : Order by problem



ole90
08-30-2007, 10:52 PM
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?

matak
08-30-2007, 11:03 PM
sort() (http://www.php.net/sort)

For more info, give more info :)

Fumigator
08-30-2007, 11:35 PM
You can sort your query results using the ORDER BY clause in the query, i.e.


SELECT * FROM items WHERE ID = '99999'
ORDER BY itemname


By the way, you can combine both of your queries into one using a join:


SELECT *
FROM items
JOIN inventory
ON items.ID = inventory.itemid
ORDER BY items.itemname



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum