Forum Moderators: coopster

Message Too Old, No Replies

Mysql Query Sort Alphbeticaly

need query result sorted

         

bumpaw

9:24 pm on Jul 25, 2004 (gmt 0)

10+ Year Member



I have the query result displaying fine but need it to show up alphabetically.

$query = "select * from dining where ".$town."=".$town_name." and ".$type."=".$dining_type."";
$result = mysql_query($query);

This should be the relevant code if anyone can give me a clue.

BlackRaven

3:53 am on Jul 26, 2004 (gmt 0)

10+ Year Member



could i ask what column you need to show alphabatically?
$colum is what every column you need to order is by
eg

"select * from dining where ".$town."=".$town_name." and ".$type."=".$dining_type."AND ORDER BY".$column;

coopster

1:58 pm on Jul 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You'll need to get rid of that "AND" in front of your
ORDER BY
clause, though!

Also, you can sort by more than one column.

$query = "SELECT * FROM dining WHERE $town = '$town_name' AND $type = '$dining_type' ORDER BY $town, $type";

bumpaw

6:22 pm on Jul 26, 2004 (gmt 0)

10+ Year Member



I'm trying to make this work, but no luck so far. I have been studying some more so that my question might be clarified. It is actually a column that is not in the original query that I wanted to sort by. This is supposed to show a list of dining spots by food type and location. The list should output with the business names alphabetical.

bumpaw

8:10 pm on Jul 26, 2004 (gmt 0)

10+ Year Member



Thanks to being pointed in the right direction I have it with:

$query = "select * from dining where ".$town."=".$town_name." and ".$type."=".$dining_type." order by bus_name";

Thanks again :)