PDA

View Full Version : php page offset question



Dedix
July 13th, 2001, 16:46
well, i have a script that makes a list of my datas in a table and it works fine, but if i will have a lot of entry what i want to be listed, then i want to offset the pages (eg. 50 entries per page)
i've done that yet, and works, just has a little bug, but i don't have any idea what it would be :)
exactly, if there are 50 entries in mysql database, and i set the limit to 10 per page, then the script is showing only 9 per page...or if i set the limit to 50 per page, then only 49 entries...
it says that 1-50 entries showing, just there are 49 on the list...
does anybody has any idea what may be the problem with it?


thanks in advance

gyrbo
July 13th, 2001, 16:53
Probly something with an array starting with 0. Just use [limit/page]++

Dedix
July 13th, 2001, 17:02
$pages=intval($numrows/$limit);
if ($numrows%$limit) {
$pages++;
}
echo"<center>";
$first_record = $offset + 1;
echo "now showing: $first_record -";
if (!((($offset)/$limit)+1==$pages)) {
$last_record = $offset + $limit;
echo " $last_record of $numrows items &nbsp; &nbsp; ";
} else {
echo " $numrows of $numrows item(s) &nbsp; &nbsp; ";
}
if ($offset != 0) { //bypass PREV link if offset is 0
$prevoffset=$offset-$limit;
echo "<a href='".$rel_path."index.$phpExt?page=members&offset=$prevoffset'>prev</a> &nbsp; \n";
}
if ( $pages != 1 ) {
for ($i=1;$i<=$pages;$i++) {
$newoffset=$limit*($i-1);
if ( ((($offset)/$limit)==($i-1)) ) {
echo "$i &nbsp; \n";
} else {
echo "<a href='".$rel_path."index.$phpExt?page=members&offset=$newoffset'>$i</a> &nbsp; \n";
}
}
}
if (!((($offset)/$limit)+1==$pages) && $pages!=1) {
$newoffset=$offset+$limit;
echo "<a href='".$rel_path."index.$phpExt?page=members&offset=$newoffset'>next</a><p>\n";
}
echo"</center>";




here is portion of the code, maybe it says more about my prob.