next, previous row.... my code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Artenis
Forum Newbie
Posts: 6
Joined: Fri Jul 11, 2008 4:54 pm

next, previous row.... my code

Post 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! :)
vetrivel
Forum Newbie
Posts: 7
Joined: Thu Aug 07, 2008 5:54 am

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

Post 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?
toraj58
Forum Newbie
Posts: 12
Joined: Sun Jun 15, 2008 12:40 am

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

Post 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]
Post Reply