Get Next and Previous Links with MySQL and PHP
Simple code for adding next and previous links to navigate between records.
$navquery= "SELECT(
SELECT id FROM table
WHERE id < '".$current_id."' ORDER BY id DESC LIMIT 1
) AS previd, (
SELECT id FROM table
WHERE id > '".$current_id."' ORDER BY id ASC LIMIT 1
) AS nextid";
$navresult = mysql_query($navquery);
$navrow = mysql_fetch_array($navresult);
$previd = $navrow['previd'];
$nextid = $navrow['nextid'];
echo "Previous ID = ".$previd." - Next ID = ".$nextid;
Written by Irene Pilato
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#