leszekmk Posted March 9, 2004 Share Posted March 9, 2004 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"> Quote Link to comment https://forums.phpfreaks.com/topic/1732-ordering-recordsets-by-multiple-fields/ Share on other sites More sharing options...
leszekmk Posted March 12, 2004 Author Share Posted March 12, 2004 Problem solved. You need to specify order of sorting (ASC or DESC) after each column name. Quote Link to comment https://forums.phpfreaks.com/topic/1732-ordering-recordsets-by-multiple-fields/#findComment-5658 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.