Re: prev next links
| From: | Joel Boonstra | Date: | Mon, 04 Feb 2002 16:00:11 +0000 |
| Subject: | Re: prev next links | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83406@lists.php.net to get a copy of this message | ||
> Does anyone know of a well written example of this? I have seen so many
> examples, but the over head just seems to be too much... does anyone have a
> smooth and well written routine?
> Regards,
> Kunal Jhunjhunwala
I think this may help out. I wrote a site that has a daily devotional on
it, and contains links to previous and next days. Here's the code:
<?php
// assume that $month, $day, $year, contain the current month, day, year
// could also use direct calls to date() instead, if this is for today
list ($prev_year, $prev_month, $prev_day) =
split (" ", date("Y m d", mktime(0,0,0,$month,$day-1,$year)));
list ($next_year, $next_month, $next_day) =
split (" ", date("Y m d", mktime(0,0,0,$month,$day+1,$year)));
// build your links
// this will, of course, change with your dating schema
$prev_link = "http://yourdomain.com/?$prev_year-$prev_month-$prev_day;
$next_link = "http://yourdomain.com/?$next_year-$next_month-$next_day;
// display them
print "<a href=\"$prev_link\">yesterday</a><br>";
print "<a href=\"$next_link\">tomorrow</a>";
?>
This doesn't take into account whether or not yesterday or tomorrow's
objects or files or whatever actually exists. Since that is
site-specific, you'll need to add that sort of logic yourself.
Hope that helps!
--
[ joel boonstra | jboonstra@gospelcom.net ]