I have done many searches to implement prev & next links for my site. I got it to work, but not how I need it to work. I have a list of jokes that display the title, when someone clicks on the title it opens up to display the joke. Now on that page I want to be able to go directly to the prev or next in the database. The way I have it now is it just grabs the id # and +1 for next and -1 for prev, which is not good, because it will go to an id page that doesn't exist. For example, if my database has 4 rows with id's (3,5,6,7), it will try and goto 1,2,4,8 and display nothing on the page. What I think I need to do is put all id's in an array and create a script that will only display the prev & next when needed and only display pages in the database.
include ("includes/db_connect.php");
global $jokes_id;
$result = mysql_query("SELECT jokes_id, title, author, joke_body, DATE_FORMAT(post_date, '%M %e `%y') as dated FROM jokes WHERE jokes_id = '$jokes_id'");
mysql_close($db_connect);
while($row = mysql_fetch_array($result)){
$title = htmlentities ($row['title']);
$author = htmlentities ($row['author']);
$joke_body = nl2br ($row['joke_body']);
$date = ($row['dated']);
//navigation start
$id = $_GET['jokes_id'];
$link = 'jokes_single.php?jokes_id=';
$next = $prev = $id;
$next++;
$prev--;
$next = $link.$next;
$prev = $link.$prev;
//navigation end
echo "<tr>\n<td width=\"110\" align=\"center\" bgcolor=\"#EEEEEE\" height=\"50\">\n";
echo "<p class=\"joke_info\"><i>Submitted by:</i><br />\n";
echo "$author</p></td>\n";
echo "<td width=\"400\" align=\"center\" bgcolor=\"#EEEEEE\" height=\"50\">\n";
echo "<p class=\"joke_title\">$title</p>\n</td>\n";
echo "<td width=\"110\" align=\"center\" bgcolor=\"#EEEEEE\" height=\"50\">\n";
echo "<p class=\"joke_info\"><i>Date posted:</i><br />\n";
echo "$date</p></font></td>\n</tr>\n";
echo "<tr>\n<td width=\"620\" align=\"left\" colspan=\"3\">\n";
echo "<p class=\"jokes\">$joke_body</p>\n<br /></td>\n</tr>\n";
echo "<tr>\n<td width=\"620\" align=\"center\" colspan=\"3\">\n";
echo '<a href="'.$prev.'">Prev </a> <a href="'.$next.'"> Next</a></td></tr>';
}
If someone can help me get this figured out, I would appreciate it.