Mr Chris Posted April 10, 2007 Share Posted April 10, 2007 Hi Guys, Wondering if someone could help me with a Previous || Next script I’m working on: Now what I want to do is: Load a story from the database and the user can click on the previous and next buttons to go to the next story in the database Now I’ve set-up this script which works, but it has floors: <?php $story_id = $_GET['story_id']; $link = '/index.php?story_id='; echo '[<a href="',$link,$story_id-1,'">Prev</a>] || [<a href="',$link,$story_id+1,'">Next</a>]'; ?> Problem Say I’m on the page index.php?story_id=1 and click on next and there is no index.php?story_id=2 (as it’s been deleted), but the next record in the database is story_id=5? - how can I make the code see that? Thanks Chris Link to comment https://forums.phpfreaks.com/topic/46392-previous-next-script-help/ Share on other sites More sharing options...
hackerkts Posted April 10, 2007 Share Posted April 10, 2007 You can do a sql query above the next and previous button. Link to comment https://forums.phpfreaks.com/topic/46392-previous-next-script-help/#findComment-225637 Share on other sites More sharing options...
Mr Chris Posted April 10, 2007 Author Share Posted April 10, 2007 Thanks, but if I do that: <?php $story_id = $_GET['story_id']; $link = '/index.php?story_id='; $SQL = "Select * FROM cms_stories where section='news' LIMIT 1"; $result = mysql_query($SQL) OR die(mysql_error()); while ($row = mysql_fetch_assoc($result)){ echo '[<a href="',$link,$story_id-1,'">Prev</a>] || [<a href="',$link,$story_id+1,'">Next</a>]'; } ?> It ignores the query and just outputs the next and previous numbers - ie if I was on story 118: previous comes out as: 117 next comes out as:119 Nomatter if the section=news or not? Any advice please? Thanks Chris Link to comment https://forums.phpfreaks.com/topic/46392-previous-next-script-help/#findComment-225699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.