Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm having a problem with something for far too long and I'm hoping that someone will see what I'm doing wrong.
I have a calendar that pulls events from an RSS feed and it works pretty well. The problem is that I don't want the user to be able to see months more than a year in the future or any months in the past and I'm having trouble adding just the right number of constraints.
Here's the logic I want it to useCode: Select all
// if date doesn't exceed one year from now, don't display forward link
// if this month isn't january and displayed month isn't december
// or if they are looking at next year but not more than 12 months away
show link to next month
// otherwise don't show next link
//if date = now, don't display backwards link
// if future months are being displayed
// and if month is less than current month while year is greater
show link to next month
// otherwise don't show previous linkCode: Select all
// make sure date doesn't exceed one year from now
$cur_mon = intval(date(m));
$cur_year = intval(date(Y));
print($cur_year);
print("<br/>");
print($cur_mon . " " . $month_num);//month_num gets passed in the query string and is how it knows which month to display.
print("<br/>");
print(date(Y)+1 . " " . $year);
// if date doesn't exceed one year from now, don't display forward link
// if this month isn't january and displayed month isn't december
if((date('mon') == 1 && $month_num == 12) ||
// or if they are looking at next year but not more than 12 months away
($year == $cur_year + 1 && $month_num >= $cur_mon))
{
$next = "<a href=\"index.html?month_num=$month_num&year_now=$year&dir=f\">Next Month</a>";
}
// otherwise don't show next link
else
{
$next = "";
print("can't go for");
}
//if date = now, don't display backwards link
// if future months are being displayed
if(($month_num > date('mon') && $year >= date('year')) &&
// and if month is less than current month but year is greater
($month_num < date('mon') && $year == $year+1))
{
$prev = "<a href=\"index.html?month_num=$month_num&year_now=$year&dir=b\">Previous Month</a>";
}
// otherwise don't show previous link
else
{
$prev="";
}
// print calendar month
print "
<table width=\"350\">
<tr><td style=\"padding-left: 125px; color:#003366; text-decoration: none; font-size: 1em; font-weight: normal;\"><a href=\"index.html\">Back to $this_month, $this_year</a></td></tr>
<tr><td><a href=\"index.html?month_num=$month_num&year_now=$year&dir=b\">Previous Month</a></td>
<td align=right><a href=\"index.html?month_num=$month_num&year_now=$year&dir=f\">Next Month</a></td>
</tr>
</table>".here's a link to the calendar: http://bfa.cctsbaltimore.org/bfa_dev/ca ... index.html
hawleyjr | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]