Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional PHP6
This is the forum to discuss the Wrox book Professional PHP6 by Edward Lecky-Thompson, Steven Nowicki; ISBN: 9780470395097
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP6 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 Display Modes
  #1 (permalink)  
Old April 8th, 2013, 12:57 PM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Indiana, United States
Posts: 13
Thanks: 3
Thanked 1 Time in 1 Post
Exclamation Chapter 6 dbtest.php Error

As I am working through the book, I am finding small errors. I didn't see this posted anywhere so I thought that I would post it here.

On page 131, the code for dbtest.php incorrectly loops over the $arRowHash:

PHP Code:
$objHandle pg_connect("host=localhost port=5432 dbname=chaptersix user=chaptersix password=chaptersix");

if (!
$objHandle) {
    echo 
"An error occurred connecting.\n";
    exit;
}
$objResult pg_query($objHandle"SELECT * FROM \"user\"");
if (!
$objResult) {
    echo 
"An error occurred querying.\n";
    exit;
}
$arRowHash pg_fetch_all($objResult);

print 
"Number Of Rows: ".count($arRowHash)."\n";

// ----------------------------------------------------------------------------
// The error is here....
//
// The for loop would never execute since the
// variable $i would never be larger than the count of
// the variable $arRowHash.
//
// Should be
// for ($i = 0; $i <= (count($arRowHash) - 1); $i++
//
// Notice that changed the conditional so that the for
// loop would execute until the variable $i is larger
// than the count of $arRowHash minus one.
// -----------------------------------------------------------------------------
for ($i 0$i >= (count($arRowHash) - 1); $i++) {
    
    print 
"Row $i\n";
    
    foreach (
$arRowHash[$i] as $key => $value) {
        print 
" - Column $key, value $value<br />\n";
    }
}

pg_close($objHandle); 
Enjoy....
  #2 (permalink)  
Old April 8th, 2013, 12:59 PM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Indiana, United States
Posts: 13
Thanks: 3
Thanked 1 Time in 1 Post
Default

Note that the code download has it correct, but the code in the book is incorrect.
  #3 (permalink)  
Old April 9th, 2013, 02:02 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Location: Indiana
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I was wondering about that.
 


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
Chapter 6, Ajax File Manager, error in upload.php file kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 4 June 4th, 2010 08:46 PM
Chapter 13: Error in user.php pherank BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 4th, 2008 09:09 PM
chapter 10 Emailing with php - firstmail.php vijdev BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 19th, 2007 01:12 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 09:57 AM
Error in simple_mailer.php ( Chapter 15 ) dwfresh Beginning PHP 3 November 26th, 2003 07:25 PM



All times are GMT -4. The time now is 10:11 PM.


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