Sort by Alphabetical Order (solved)

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Sort by Alphabetical Order (solved)

Post 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!
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: Sort by Alphabetical Order

Post 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.
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Re: Sort by Alphabetical Order

Post 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!
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Sort by Alphabetical Order (solved)

Post by SpiritWebb »

Changed this thread to solved based on Tim's answer as this worked perfectly!
Image

Image
Post Reply

Return to “Beginner Help and Support”