Page 1 of 1

Sort by Alphabetical Order (solved)

Posted: Sun Jun 19, 2011 7:52 pm
by Tim
How could I sort the output of this while loop by alphabetical order?

Code: Select all

<form action = "admin_panel.php" method = "post">		
<br><br>		
<b>Give a player an item:</b>		
<br>		
Username: <input type = "text" name = "username" size = "10" />      		
Item:		
<select name="item_name">      		
		
<?php
$item_list_1 = "SELECT * from items";
$item_list_2 = mysql_query($item_list_1) or die ("System: Could not get item information.");

while($item_list_3 = mysql_fetch_array($item_list_2))
{
	echo "<option>$item_list_3[name]</option>";
}
?>
		
</select>
     
Quantity: <input type="text" name="item_quantity" size = "10" />      
<input type="submit" value="Submit" name="give_item">		
</form>
I'm sure it's pretty easy. I tried to figure it out by reading the types or sorting in the PHP manual, but I just couldn't get it to work ...

Please and thank you!

Re: Sort by Alphabetical Order

Posted: Sun Jun 19, 2011 8:02 pm
by Perry
I'm not sure because I have never sorted alphabetically, but you could try changing " $item_list_1 = "SELECT * from items"; " to " $item_list_1 = "SELECT * from items ORDER BY name"; ".

name would be what ever table you are using to store the items name.

Let me know if it helps.

EDIT: Yes I just tried it and it should do what you want.

Re: Sort by Alphabetical Order

Posted: Sun Jun 19, 2011 8:15 pm
by Tim
Perry wrote:I'm not sure because I have never sorted alphabetically, but you could try changing " $item_list_1 = "SELECT * from items"; " to " $item_list_1 = "SELECT * from items ORDER BY name"; ".

name would be what ever table you are using to store the items name.

Let me know if it helps.

EDIT: Yes I just tried it and it should do what you want.
That worked perfectly! Thank you Perry!

Re: Sort by Alphabetical Order (solved)

Posted: Sun Jun 19, 2011 8:33 pm
by SpiritWebb
Changed this thread to solved based on Tim's answer as this worked perfectly!