p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 (http://p2p.wrox.com/book-beginning-php4-php-5-isbn-978-0-7645-4364-7-v5-isbn-978-0-7645-5783-5-33/)
-   -   Chapter 12 userview.php pagination problem solved (http://p2p.wrox.com/book-beginning-php4-php-5-isbn-978-0-7645-4364-7-v5-isbn-978-0-7645-5783-5/91265-chapter-12-userview-php-pagination-problem-solved.html)

freckleboy October 25th, 2013 09:38 AM

Chapter 12 userview.php pagination problem solved
 
Just dived into this book after several years on the shelf for a specific project. As others have posted I was having trouble with the pagination. The same set of database record kept loading whenever [Next] or [Bottom] was clicked.

I realised it was because whenever the list_records function was called from a query string the global $cur_page variable was initialised all over again thus ignoring the value passed in the query string!

To get over this I removed the $cur_page variable from the global declaration and added the following just after the remaining global variable declarations:

PHP Code:

if (!isset($_GET['cur_page'])) {
        
$cur_page 0;
    } else {
        
$cur_page $_GET['cur_page'];
    } 

So now this checks if the $cur_page variable is not(set and not null) in the superglobal array $_GET. If this is the case it is initialised with 0. If not then it is assigned to the value passed in the query string thus preserving the value intended.

Hope that is clear and helps someone who may be pulling their hair out as I was!

freckleboy October 29th, 2013 07:09 AM

_All_ I need to do now is figure out why the columns don't sort and the view_record function does not work - haha!
Think it may the the global declarations again.


All times are GMT -4. The time now is 05:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.