Previous and Next code problem

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
rosslad2004
Forum Newbie
Posts: 5
Joined: Fri Feb 18, 2005 2:34 pm

Previous and Next code problem

Post by rosslad2004 »

Hi there.

I have the following code:

Code: Select all

$totalrows = $fcount[friends]; 
$limit = 10; 
if(!$page){ 
$page = 1; 
} 
$limitvalue = $page * $limit - ($limit);
then the Select query ending with

Code: Select all

LIMIT $limitvalue,$limit"
and the Previous and Next codes:

Code: Select all

if($page != "1"){ 
$pageprev = $page - 1; 
echo "[<a href='test.php?page=$pageprev'>Previous</a>]"; 
} 
$numofpages = $totalrows / $limit; 
$numofpages = ceil($numofpages); 
for($j = 1; $j <= $numofpages; $j++) { 
if($j == $page){ 
echo "[$page]"; 
} 
else{ 
echo "[<a href='test.php?page=$j'>$j</a>]"; 
} 
} 
if(($totalrows  = ($limit * $page)) > 0){ 
$pagenext = $page + 1; 
echo "[<a href='test.php?page=$pagenext'>Next</a>]"; 
}
Everything works except for the Next link which always appears even if there are no more rows to show :evil:

for example if there are only 10 rows in the database table and my limit is to show 10 rows per page the Next link will still show which i don't want it to.

Can anybody see a problem with the above code that could be causing this problem?

Any help would me greatly appreciated.

Thanks in advance
Ross
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Code: Select all

if(($totalrows  = ($limit * $page)) > 0){
You want to use the comparison operator "=="


(doh') :-)
rosslad2004
Forum Newbie
Posts: 5
Joined: Fri Feb 18, 2005 2:34 pm

Post by rosslad2004 »

Thanks jshpro2

but that don't seem to work either
if i place "==" into

Code: Select all

if(($totalrows  = ($limit * $page)) > 0){
the next link does not appear at all :?

Kind Regards
Ross
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You allready have $numofpages and $page

Code: Select all

if ($page < $numofpages)
{
  echo 'generate link to next page';
}
rosslad2004
Forum Newbie
Posts: 5
Joined: Fri Feb 18, 2005 2:34 pm

Post by rosslad2004 »

thank you also timvw

the next link does not appear with that either.

This has got me stumped :(

Kind Regards
Ross
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Might want to prepend

Code: Select all

ini_set('error_reporting', E_ALL);
ini_set('display_errors');
And check if $totalrows is what you expect it to be...

Btw, the following is "dirty":

Code: Select all

$totalrows = $fcount[friends];
Better write it as

Code: Select all

$totalrows = $fcount['friends'];
Post Reply