Jump to content

Archived

This topic is now archived and is closed to further replies.

leszekmk

Ordering recordsets by multiple fields

Recommended Posts

Hi,

I am trying to sort the table where I store a date in separate cells (year, month, day). When listing the ouput I want the date to be sorted either in ASC or DESC order. However, only last column in the $column variable is sorted, no matter how many columns are included in the variable. In this case I end up with sorted days but the months are not sorted. This makes me think that I cannot sort on more than one criteria (column). Am I correct? Is there a way to sort the tables in Dreamweaver on more than one criteria? Please help. Below is the code with portions eliminated for clarity.

 

 

<?php
$sort = ($_GET['sort']);
$column = ($_GET['column']);
if (!$sort)
{
 $sort = "ASC";
}
if (!$column)
{
$column = "eventinfo.eventyear,eventinfo.eventmonth,eventinfo.eventday";
}

mysql_select_db($database, $connection);
$query_rsEventData = "SELECT eventinfo.eventmonth, eventinfo.eventday, eventinfo.eventyear FROM eventinfo WHERE ... ORDER BY $column $sort";

if ($sort == "ASC")
{
$sort = "DESC";
}
else
{
$sort = "ASC";
}
?>


<a href = "file.php?sort=<?php echo "$sort";?>&column=eventinfo.eventyear,eventinfo.eventmonth,eventinfo.eventday">

 

 

Share this post


Link to post
Share on other sites

Problem solved. You need to specify order of sorting (ASC or DESC) after each column name.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.