I've got this code below. Right now it is ordering everything by 'date1' in my mySQL database. But, in the database I am going to have date1, date2, date3, date4. When date1 expires, it is no longer displayed, in which case, I need it to then sort by the date2 for that row. Or if date 1 and 2 are expired, then I need ot to sort that row by date3. So, in every row, there will be expiring dates. It's as though I need another field in the database that somehow learns which date is should be sorted by. I just have no idea how to do that.
How can I accomplish this? Any ideas? If you need more explanation as to what I'm trying to do, please let me know. I need to get this working as soon as I can.
<?php
$db->query("SELECT * FROM gtraining WHERE start_date<NOW() AND end_date>NOW() ORDER BY date1");
while($db->fetch()) {
echo "<h4>" . $db->row['title'] . "</h4>\n";
echo "<p>";
for ($i=0; $i<4; $i++) {
if (($db->row['date'.($i + 1)] > date('YmdHis')) && ($db->row['location'.($i + 1)] != "")) {
echo $db->row['location'.($i + 1)] . ": " . $db->row['dates_times'.($i + 1)] . "<br />\n";
}
}
echo "<p>" . $db->row['description'] . "</p>\n";
if ($db->row['link_text'] != "") {
echo "<p><img src=\"/g/link.gif\" class=\"icon\" target=\"_blank\" /> <a href=\"" . $db->row['link_url'] . "\">" . $db->row['link_text'] . "</a></p><p><br /></p>";
} else {
echo "</p><p><br /></p>";
}
}
?>