Page 1 of 1

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

Posted: Mon Apr 04, 2011 4:22 pm
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>";
}