PDA

View Full Version : How do I make my PHP thing list in name order?



incka
12-07-2003, 02:19 PM
How do I make my PHP thing list in name order?

It's listing by ID autonumber, but I want to have them listed by name, what should I do...

I'm only posting this cause I can't find Mike anywhere...

GCT13
12-07-2003, 04:15 PM
If you're querying your data from a database, put:

order by name asc

at the end of your sql query, where name is the name of the column you want to sort by. Are you using a database?

Mike
12-08-2003, 07:41 AM
Originally posted by incka
I'm only posting this cause I can't find Mike anywhere...

I've got flu:(

Westech
12-08-2003, 09:43 AM
Well cover your mouth when you type. I don't want to get sick!

incka
12-08-2003, 10:25 AM
Poor Mike...

This is the code I'm using minus the log in details...



<?php

//connect
$connect = mysql_connect("localhost", "dbname", "password");

//select db
mysql_select_db("dbname", $connect);

//query db
$result = mysql_query("SELECT * FROM games WHERE Category='Adventure'", $connect);

//start table
echo ("<table>");

//list all games in table
for ($x=0; $x < mysql_num_rows($result); $x++)
{
$row = mysql_fetch_assoc($result) ;

echo ("<tr style='padding-top:10'>");
echo ("<td><a href='http://www.games2go.co.uk/game/");
echo $row['URL'];
echo ("'>");
echo ("<img src='");
echo $row['ImageURL'];
echo ("' border='0' width='70' height='59'>");
echo ("</a>");
echo ("</td>");

echo ("<td style='padding-left:10'><font color='000000'><b>");
echo ("<a href='http://www.games2go.co.uk/game/");
echo $row['URL'];
echo ("'>");
echo $row['Name'];
echo ("</font></a></b>");
echo (": ");
echo $row['Description'];
echo ("</td></tr>");

}

?>

GCT13
12-08-2003, 03:48 PM
incka, did you try my suggestion?


$result = mysql_query("SELECT * FROM games WHERE Category = 'Adventure' order by Name asc", $connect);

incka
12-09-2003, 12:31 AM
I'll try it now... Before when you posted it I didn't know where to put it, but i understand now... I'll try it out when I get to my computer... Thank you :)

bugsy
12-10-2003, 03:52 PM
The "order by ____ ASC or DESC" is what you need (as mentioned earlier).

In case you're wondering, ASC is short for ascending and DESC is short for descending.

Mike
12-11-2003, 07:18 AM
Never knew that:)