Jump to content


Photo

Ordering recordsets by multiple fields


  • Please log in to reply
1 reply to this topic

#1 leszekmk

leszekmk
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 09 March 2004 - 09:39 PM

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">




#2 leszekmk

leszekmk
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 12 March 2004 - 05:31 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users