I just made a table sortable by column headers by reading a thread
posted here a while ago. Here is the code simplified:
$sort_order = 'id';
if($order == 'jobtitle'){
$sort_order = 'jobtitle';
}else if($order == 'district'){
$sort_order = 'district';
}
else if($order == 'date'){
$sort_order = 'date';
}
"SELECT * FROM table ORDER BY $sort_order ASC";
It works just as I thought it would. But, my question is how do I make
it so 'id' (set to auto increment) or 'date' defaults to DESC (so the
most recent post is always on top), while at the same time the links on
the column headers sorts by ASC (like it currently does).
Thanks.
posted here a while ago. Here is the code simplified:
$sort_order = 'id';
if($order == 'jobtitle'){
$sort_order = 'jobtitle';
}else if($order == 'district'){
$sort_order = 'district';
}
else if($order == 'date'){
$sort_order = 'date';
}
"SELECT * FROM table ORDER BY $sort_order ASC";
It works just as I thought it would. But, my question is how do I make
it so 'id' (set to auto increment) or 'date' defaults to DESC (so the
most recent post is always on top), while at the same time the links on
the column headers sorts by ASC (like it currently does).
Thanks.
Comment