Hi
I'm working on a content management system. One of the features I've been working on is implementing an editing feature which when you load the page by default shows the news items for the current month but with links to go back a month and forward a month
The problem comes in this..
I have this code
if ((!$m) || (!$y))
{
$m = date("m",mktime());
$y = date("Y",mktime());
}
$query = "SELECT id, section_id, headline, url, date_format(date,'%a %D %M %Y @ %H:%i%p'), body FROM sections_news WHERE date_format(date, '%m') = '$m' AND date_format(date, '%Y') = '$y' ORDER BY date DESC";
$format_m = sprintf( "%02d", $m);
Print ("$format_m $y<BR>");
?>
<BR>
<A HREF="<?=$SCRIPT_NAME?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><< Prev</A> ---
<A HREF="<?=$SCRIPT_NAME?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">Next >></A>
When it comes to doing the links in the last part my code takes 1 or adds one to the month. Only, it makes for example 07 into 7 (thus buggering up the mysql query. I'm looking for perhaps a better way of doing prev and next (or at least a way of validating the numbers.
I have tried $format_m = sprintf( "%02d", $m); which does work but once inside the <A HREF= it doesn't work.
Thanks
MD