...

View Full Version : Paging - pages are multiplying!



ron08
03-12-2008, 04:27 AM
Hi everybody,

Exactly what the title says! :( And the funny thing is that if I click on page no.1 I get 10 results, if I click page no.2 I get 20 results, page no.3 30 results and so on... What am I doing wrong?

Here's my code:



<?
if (!(isset($start))) { $start=0; }
$maxperpage=10;
$tend = $start+$maxperpage;

$ SOME SQL QUERY = (" ... LIMIT $start,$tend")
?>


****HERE I GET THE SQL RESULTS-OUTCOME****

and then towards the end of the page, I have the following code:

<a href=URL&start=0\">1</a>");



<?
$more= mysql_query("SELECT * FROM * WHERE *** ") or die(mysql_error());
$more2= mysql_num_rows($more);
$maxpage = ceil($divide/$maxperpage);
if (($more2/$maxperpage)>$maxpage) { $maxpage=$maxpage+1; }
for ($j=1;$j<$maxpage;$j++){
$cs = ($j*$maxperpage); $cp = $j+1;
print(" | <a href=URL&start=$cs>$cp</a>");
}
?>

The outcome of the code above is like this:

Pages: 1, 2, 3, 4, 5 etc.

and every time I click on any number I get the SQL results-records multiplied by 10 (e.g. if I click on 3 I get 30 results per page, on 5 I get 50! etc).

Any help would be GREATLY appreciated! :thumbsup:

Inigoesdr
03-12-2008, 12:10 PM
Hi everybody,

Exactly what the title says! :( And the funny thing is that if I click on page no.1 I get 10 results, if I click page no.2 I get 20 results, page no.3 30 results and so on... What am I doing wrong?

Here's my code:

<?
if (!(isset($start))) { $start=0; }
$maxperpage=10;
$tend = $start+$maxperpage;

$ SOME SQL QUERY = (" ... LIMIT $start,$tend")
?>

****HERE I GET THE SQL RESULTS-OUTCOME****

and then towards the end of the page, I have the following code:

<a href=URL&start=0\">1</a>");

<?
$more= mysql_query("SELECT * FROM * WHERE *** ") or die(mysql_error());
$more2= mysql_num_rows($more);
$maxpage = ceil($divide/$maxperpage);
if (($more2/$maxperpage)>$maxpage) { $maxpage=$maxpage+1; }
for ($j=1;$j<$maxpage;$j++){
$cs = ($j*$maxperpage); $cp = $j+1;
print(" | <a href=URL&start=$cs>$cp</a>");
}
?>

The outcome of the code above is like this:

Pages: 1, 2, 3, 4, 5 etc.

and every time I click on any number I get the SQL results-records multiplied by 10 (e.g. if I click on 3 I get 30 results per page, on 5 I get 50! etc).

Any help would be GREATLY appreciated! :thumbsup:
You're multiplying it in your code, the displaying the multiplied number in the link.

Please remember to read the stickies for this forum. In particular the one about using
tags (http://www.codingforums.com/showthread.php?t=68462) when posting code.

dumpfi
03-12-2008, 06:42 PM
The second argument to LIMIT specifies the number of rows that are returned, and not an offset into the result set.

That's why you have to change:
$tend = $start+$maxperpage;to
$tend = $maxperpage;dumpfi



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum