Jump to content

[SOLVED] isn't echoing the last element!!!


thefortrees

Recommended Posts

Hi all -

 

In this loop, the last element isn't being echoed with the html option the last time through. I put an echo statement before the if-else to debug, and it echoed every value. So, for some reason, the loop is breaking before it gets to the echo HTML the last time through. Any ideas?

 

$temp = array();
				$val = array_search($row['lob'], $businessArray);
				$temp[] = $businessArray[$val];			
				$count = 0;

					//for ($i = 0; $i < sizeof($businessArray); $i++){
					foreach ($businessArray as $value){
						//$value = $businessArray[$i];	

						if ($value == $row['lob']){
							continue;
						}
						else{
							$temp[] = $value;			
							echo
								"<option value='" . $temp[$count] . "'>" . $temp[$count];	
							$count++;
						}
					}

Link to comment
Share on other sites

I appreciate your response Corona.

 

The element $row['lob'] is not the last element in the array. In the select menu, $row['lob] is displayed first (this loop is nested in another loop) multiple times. If I remove the conditional continue, then $row['lob'] is repeated twice in the loop....

Link to comment
Share on other sites

Sure thing! It's just a while loop with mysql_fetch_array.

 

//Display each question.
			while($row = mysql_fetch_array($result)){
				echo
					"<form>" .
					"<tr><td><input type='text' name='question' value='" . $row['question'] . "'></td>" . 
					"<input type='hidden' name='questions_id' value='" . $row['questions_id'] . "'>" .			
					//Create drop down menu for LoB for each question.
					"<td><select name='lob'>";


				$temp = array();
				$val = array_search($row['lob'], $businessArray);
				$temp[] = $businessArray[$val];			
				$count = 0;

					//for ($i = 0; $i < sizeof($businessArray); $i++){
					foreach ($businessArray as $value){
						//$value = $businessArray[$i];	

						if ($value == $row['lob']){
							continue;
						}
						else{
							$temp[] = $value;			
							echo
								"<option value='" . $temp[$count] . "'>" . $temp[$count];	
							$count++;
						}
					}
				echo
					"</select></td>" .
					"<td><h6><input type='submit' name='updateQuestion' value='Update'></h6></td>" .
					"<td><h6><input type='submit' name='deleteQuestion' value='Delete'></a></h6></td></tr>" .
					"</form>";


			}
		}

Link to comment
Share on other sites

Ok... I see the problem now.  The problem is you increment $count AFTER you output your option code.

 

Instead of doing that... just do this:

echo "<option value='" . $value . "'>" . $value;

Since you already have your value just use it.

 

Link to comment
Share on other sites

foreach ($businessArray as $value){

                                                  $count++;

//$value = $businessArray[$i];

 

if ($value == $row['lob']){

continue;

}

else{

$temp[] = $value;

echo

"<option value='" . $temp[$count] . "'>" . $temp[$count];

 

}

}

 

 

counter i guess should be at the top of the condition or echo you will not get the last resulr just because the counter is not being updated on the last round of the counter

 

ASTIG!!! :-* :-*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.