Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP for loop not executing 2nd of 2 iterations

Posted on 2011-09-10
5
Medium Priority
?
358 Views
Last Modified: 2012-05-12
Can't seem to get the second array element to print out...please help!
There are two campers, each with a complete set of information, in the array
$displayCampersOfParent

The current display only shows the first camper's information, and then the for loop terminates...
<?php
		// insert short blocks for parent, all campers
		/*echo '<pre>';
		print_r($displayCampersOfParent);
		echo '</pre>';*/
		
		// display camper name, selection of sessions
		for ($i = 0; $i < count($displayCampersOfParent); $i++){
			
			// set camper number loop
			$loop_counter = 1;
			echo $loop_counter;
			
			echo '<dl><h3>';
			echo $displayCampersOfParent[$i]['t_firstname_en'] .' ';
			echo $displayCampersOfParent[$i]['t_lastname_en'];
			echo '</h3>';
			if ($_SESSION['UserLang'] == 'JP'){
				echo '<br />';
				echo $displayCampersOfParent[$i]['t_lastname_jp'] .' ';
				echo $displayCampersOfParent[$i]['t_firstname_jp'];
			}
			echo '<br />';
			
			// display 3 session selection blocks
			for ($session_loop_counter = 1; $session_loop_counter < 4; $session_loop_counter++){
				
				echo '<dt><span class="NoStarRequired">* </span>';
				echo $CampSessionSelection;
				echo '</dt><dd>';
				echo '<select name="';
					echo 'Camper_' .$loop_counter .'_Session_' 
						.$session_loop_counter .'_List'; 
					echo '" ';
					echo 'id="';
					echo 'Camper_' .$loop_counter .'_Session_' 
						.$session_loop_counter .'_List'; 
					echo '">';
					echo '<option value="">';
					echo $CamperSessionOptions; 
					echo '</option>';
					for ($i = 0; $i < count($obj->mRegSessions); $i++){
					  
						  // build session dates
						  $date_start = date_create($obj->mRegSessions[$i]['d_startdate']);
						  $date_end = date_create($obj->mRegSessions[$i]['d_enddate']);
						  $print_date_start = date_format($date_start, 'n/d/Y');
						  if ($date_start == $date_end){
							  $print_date_end = '';
						  } else {
							  $print_date_end = date_format($date_end, 'n/d/Y');
						  }
						  
						  // output session dates
						  if ($_SESSION['UserLang'] == 'EN'){
							  $ProgramName = $obj->mRegSessions[$i]['t_program_name_en'];
							  $SessionName = $obj->mRegSessions[$i]['t_session_name_en'];
						  } else {
							  $ProgramName = $obj->mRegSessions[$i]['t_program_name_jp'];
							  $SessionName = $obj->mRegSessions[$i]['t_session_name_jp'];
						  }
							  
						  if ($SessionName == '') {
							  echo '<option value="' .$obj->mRegSessions[$i]['pk_session'] .'">'
							  .$ProgramName ."&nbsp;&nbsp;" .$print_date_start 
							  ." &mdash; " .$print_date_end .'</option>';
						  } else {
							  echo '<option value="' .$obj->mRegSessions[$i]['pk_session'] .'">'
							  .$ProgramName .', ' .$SessionName .": " .$print_date_start 
							  ." &mdash; " .$print_date_end .'</option>';
						  }
      				 } // end for loop
    			echo '</select></dd>';
			
			// end session display for loop--3 repetitions
			}
			
			
			// end this camper's session registration block
			echo '</dl>';
			
			// increment counter
			$loop_counter++;
			echo $loop_counter;
		// end for loop, after displaying all campers	
		}
     ?>

Open in new window

0
Comment
Question by:kpisor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 total points
ID: 36517758
You reused $i as a loop counter in line 42. You initially declared it in line 8. You are most likely overwriting the value in the 2nd loop, so by the time the first loop comes around a 2nd time, you have already exceeded the bounding condition. Try using different variables for each loop.
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 36517762
I can't see the error. What do you get when you

echo count($displayCampersOfParent);

Open in new window


Can you show the output from
   	        /*echo '<pre>';
		print_r($displayCampersOfParent);
		echo '</pre>';*/

Open in new window

(without the comments)
0
 

Author Closing Comment

by:kpisor
ID: 36518237
Kaufmed,
Fantastic. I stared at this thing for 30 minutes, and never saw the two $i variables. I put in $j and it worked immediately.
Thanks!
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 36518844
@kaufmed-

d'oh. Good pickup. I missed it too.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36518975
NP. Glad to help  = )
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question