Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 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 14th, 2009, 04:23 PM
Registered User
 
Join Date: Apr 2009
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default Foreach in Chapter 6

I am confused about the use of the foreach loop described in the movie.php file in chapter 6:

PHP Code:
//populate the select options with the results
while ($row mysql_fetch_assoc($result)) {
   foreach (
$row as $value) {
     echo 
'<option value="' $row['movietype_id'] . '">';
     echo 
$row['movietype_label'] . '</option>';
  }

Why are we using a foreach loop? We are assigning values to $value and then not calling the variable in the loop; we end up calling the specific $row array values instead... this just causes everything to be repeated twice in the drop down menu.

Is this a mistake?

Thanks in advance for the help...

-Kent
 
Old April 15th, 2009, 02:54 AM
Registered User
 
Join Date: Apr 2009
Posts: 8
Thanks: 0
Thanked 1 Time in 1 Post
Default removed the foreach

I have removed the foreach loop and the code displays correctly in the browser...

If there was some purpose for the foreach, please let me know.

Thanks,
-K
 
Old January 22nd, 2010, 08:57 PM
thg thg is offline
Registered User
 
Join Date: Jan 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks

Thanks, I've been working my way through the book and had thus far been able to solve every problem, but just couldn't figure out how to make the foreach work for this. Never though to just remove it, figured it was there for some reason.

Tim





Similar Threads
Thread Thread Starter Forum Replies Last Post
foreach confusion stokerfed C# 2 June 13th, 2007 02:30 PM
ForEach Loop Bushido121 BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 October 23rd, 2006 07:55 PM
hlpe with foreach(); haryohnesa PHP Databases 1 August 3rd, 2006 12:46 PM
"foreach" error BradBrening Pro PHP 2 January 13th, 2005 05:33 PM
for loops from within foreach richard.york Pro PHP 5 October 2nd, 2003 01:54 AM





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