Click to See Complete Forum and Search --> : Previous and Next script help please?


chrisb
04-11-2007, 03:53 AM
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 that;s a news story and the user can click on the previous and next buttons to go to the next news 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=';

$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

mahfooz
04-11-2007, 06:08 AM
well try this

<?php
$story_id=$_GET['story_id'];
$next_id=$story_id+1;
$pre_id=$story_id-1;
$link = '/index.php?story_id=';
echo "[<a href='$link$next_id'>Prev</a>] || [<a href='$link$pre_id'>Next</a>]";
?>

chrisb
04-11-2007, 06:15 AM
Thanks,

But that just increments each time. I want it to specify the next record that's of the section = news - ie if i'm on record 3, record 4 may be of the section = reports or record 4 may not even exist!.

See what I mean?

Any other ideas please?

mahfooz
04-13-2007, 05:22 AM
well you will have to query again for next and previous record like



select * from table whare `news_id` > '$news_id' and section='news' limit 1

select * from table whare `news_id` < '$news_id' and section='news' limit 1


first one for next news and 2nd for prevoius record

i m not sure that it will solve ur problem , because i not testify these queries