Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Expert PHP and MySQL
BOOK: Expert PHP and MySQL
This is the forum to discuss the Wrox book Expert PHP and MySQL by Andrew Curioso, Ronald Bradford, Patrick Galbraith; ISBN: 9780470563120
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Expert PHP and MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 8th, 2012, 06:57 AM
Registered User
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 - Iterator for loop example question


I can not get my head around the best way to ensure that the books looped through in the for loop are from the correct page.

The books in the $bookList arrray appear to be all of the books and are not limited to a per page basis.

The only work around I can see is to use an if statement in the loop and use the key to test against the $page->getFirstIndex() and $page->getLastIndex() methods, such as below.

PHP Code:
for ( $bookList->rewind(); $bookList->valid(); $bookList->next() )
    if ( 
$key >= $bookPage->getFirstIndex() && $key $bookPage->getLastIndex() ) {
printf("    <tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",$book['title'], $book['author'], $book['publisher']);

Is there a simpler way to supply the for loop only the books from the page the user is on.

Will appreciate your help.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop Question smys123 JSP Basics 1 January 22nd, 2009 09:31 PM
Loop question??? RinoDM Javascript 1 May 13th, 2008 07:35 PM
Question on do while loop savoym Java Basics 2 May 3rd, 2007 05:56 AM
Do While Not Loop Question hcweb Classic ASP Basics 3 January 12th, 2007 01:27 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.