Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Expert PHP and MySQL
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 8th, 2012, 06:57 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
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.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 09:00 AM.

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