sorting mysql query with order multiple columns col1,col2...

programming with the MySQL environment and PHP or other server side languages.
Post Reply
darknkreepy3#
Site Admin
Posts: 253
Joined: Tue Oct 27, 2009 9:33 pm

sorting mysql query with order multiple columns col1,col2...

Post by darknkreepy3# »

if you make a table in your mysql db that has columns:
[year]
[month]
[day]

and of couse:
[title]
[blurb]

you can have your entries retrieved in ascending order by using this query:
Select everything from table 'events' and sort it by year then month and finally day order.

Code: Select all

$query=mysql_query("SELECT * FROM events ORDER year,month,day");
$lenE=mysql_num_rows($query);
//
for($e=0;$e<$lenE;$e++)
{
$row=mysql_fetch_assoc($query);
echo "<div id='eventnode'>".$row['month']." ".$row['day'].", ".$row['year']."<br><h3>".$row['title']".</h3><br>."$row['blurb']."</div>";
}
Post Reply