Page 1 of 1

next, previous row.... my code

Posted: Wed Sep 10, 2008 4:24 pm
by Artenis
I have two button`s, whitch switch row id: next, previous... But i dont know, how to disable the next and previous button, to stop counting up and down...
here is my code:
for example: min:3 and max:6
$up=$_GET['new']+1;
$down=$_GET['new']-1;
if($max!=$_GET['new']){
$next='?new='.$up.'';
}
else{
$next='#';
}
if($min!=$_GET['new']){
$prev='?new='.$down.'';
}
else{
$prev='#';
}
<a href="<?php echo $prev; ?>">Previous</a> <a href="<?php echo $next; ?>">Next</a>

with this script i can count: from -n tp +n, that script dont stop anything...
Please help... Previously big, big thanks!

or maybe there is some very simple scripts who do exatctly the same thing, but funkciona! :)

Re: next, previous row.... my code

Posted: Tue Sep 16, 2008 2:03 pm
by vetrivel
hey whether new is auto incremented value?
if so what happen if u deleted a row(ex:5 in your case).??????
so, what i suggest is use query to get the next and previous value
like(

Code: Select all

$next= mysql_fetch_array(mysql_query("SELECT new FROM BLABLA WHERE new > $_GET[new] order by new ASC LIMIT 0,1"));
and 
$prev= mysql_fetch_array(mysql_query("SELECT new FROM BLABLA WHERE new< $_GET[new] order by new DESC LIMIT 0,1"));
 
)
and then
<a href="<?php if(isset($prev))echo $prev; ?>">Previous</a> <a href="<?php if(isset($next)) echo $next; ?>">Next</a>

...........
note: i dint tried this..
but this will help you lot..
is there any other way to do this?

Re: next, previous row.... my code

Posted: Tue Sep 16, 2008 2:29 pm
by toraj58
i have revised your code a little bit; try this:

Code: Select all

 
[b]$bnext = $bprev = true;[/b]
$up=$_GET['new']+1;
$down=$_GET['new']-1;
if($max!=$_GET['new']){
$next='?new='.$up.'';
}
else{
$next='#';
[b]$bnext = false;[/b]
}
if($min!=$_GET['new']){
$prev='?new='.$down.'';
}
else{
$prev='#';
[b]$bprev=false;[/b]
}
<a href="<?php echo $prev; ?>">[b]<?php if ($bprev) echo Previous; ?>[/b]</a> <a href="<?php echo $next; ?>">[b]<?php if ($bnext) echo Next; ?>[/b]</a>
 
Note: I've added just two boolean variables to check for bundaries and then chech the condition with if to change the visibility of the links.

Touraj Ebrahimi [toraj_e] [at] [yahoo] [dot] [com]