I'm trying to write a query that will check to see if there are any results for a week range, and if there are, it will print out a link to a specific page. I've got it working, essentially, but the following code will print out (for example):
05 January 2006
12 January 2006
19 January 2006
I would like it to print this out in reverse order:
19 January 2006
12 January 2006
05 January 2006
Can someone help me modify the code in order to accomplish this? I've tried various sort() methods, but none have worked.
$week_start = '2005-12-01';
$number_of_weeks = 52;
make_weekly_queries($week_start, $number_of_weeks);
function make_weekly_queries($start, $number) {
$now2 = date('Y-m-d');
for ($i = 0; $i < $number; $i++) {
if ($i > 0) {
$start = add_days(7, $start);
}
if ($start < $now2) {
$query = "SELECT * FROM MyTable WHERE" .
" Expiration_Date BETWEEN '" . $start .
"' AND '" . ($end = add_days(6, $start)) ."' ORDER BY Expiration_Date DESC";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
echo '';
} else {
$st2 = date('d F Y',strtotime($start));
$st3 = date('Md',strtotime($start));
echo '<a href="listings/'.$st3.'">'.$st2.'</a><br />';
while ($row = mysql_fetch_assoc($result)) {
}
}
}
}
}
function add_days($days, $date) {
$date = date('Y-m-d', strtotime('+' . $days . ' days', strtotime($date)));
return $date;
}