Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP6
|
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 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 April 8th, 2013, 12:57 PM
Authorized User
 
Join Date: Sep 2012
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....
 
Old April 8th, 2013, 12:59 PM
Authorized User
 
Join Date: Sep 2012
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.
 
Old April 9th, 2013, 02:02 PM
Registered User
 
Join Date: Apr 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I was wondering about that.





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 10:57 AM
Error in simple_mailer.php ( Chapter 15 ) dwfresh Beginning PHP 3 November 26th, 2003 08:25 PM





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