<?
function pagination($start, $num_rows,$file,$limit) {
if(empty($limit)) {
$limit = 20;
}
if($start ==0) {
$previous_link = " ";
} else {
#$start = $start - $limit;
$previous_link = "<a href=\"$file?start=$start\">Previous
Entries</a>";
}
$pages = ceil($num_rows/$limit);
$pageNow = ceil($start/$limit);
if($pages > $pageNow) {
#$start = $start + $limit;
$next_link = "<a href=\"$file?start=$start\">Next Entries</a>";
} else {
$next_link = " ";
}
echo "<table width=\"100%\">
<tr>
<td width=\"50%\"
align=\"center\">$previous_link</td>
<td width=\"50%\"
align=\"center\">$next_link</td>
</tr>
</table>";
}
pagination(7,10,"file",5);
?>
--- In [email protected], "Conor Doyle" <[EMAIL PROTECTED]> wrote:
>
> I've got one of those problems that you know the problem is simple, but
> you've been staring at it for too long to make sense anymore.
> Basically, I have the following function to help step through a database
> by displaying Previous and Next links, depending on some variable sent
> to it.
>
> function pagination($start, $num_rows,$file,$limit) {
> if(empty($limit)) {
> $limit = 20;
> }
> if($start ==0) {
> $previous_link = " ";
> } else {
> $start = $start - $limit;
> $previous_link = "<a
> href=\"$file?start=$start\">Previous Entries</a>";
> }
> if($num_rows > ($start + $limit)) {
> $start = $start + $limit;
> $next_link = "<a href=\"$file?start=$start\">Next
> Entries</a>";
> } else {
> $next_link = " ";
> }
> echo "<table width=\"100%\">
> <tr>
> <td width=\"50%\"
> align=\"center\">$previous_link</td>
> <td width=\"50%\"
> align=\"center\">$next_link</td>
> </tr>
> </table>";
> }
>
> So $start is where to start retrieving items from the db. $num_rows is
> how many rows there are in the DB. $file is the file calling it and
> $limit is how many rows per page to display.
>
> The problem I'm having is that when calling the function with:
> pagination(5,10,"file",5);
>
> The next link continually displays. This should be incorrect as 10
> ($num_rows) is not greater than 10 ($start + $limit. Any suggestions
> will be appreciated.
>
> Thanks,
>
> Conor
>
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/php-list/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/