Jump to content

Previous || Next script help?


Mr Chris

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.