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
Register
Register | FAQ | Members List | Calendar | 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
Reply
 
Thread Tools 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

Hi,

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.

Cheers
Craig
Reply With Quote
Reply


Thread Tools
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 08: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 12:27 PM



All times are GMT -4. The time now is 04:44 PM.


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