Jump to content

[SOLVED] Error in Code - While Loop


Fearpig

Recommended Posts

Hi Guys,

Could someone take a look at my code for me?! I've made another stupid error somewhere.

 

while (odbc_fetch_row($result_Area)) 
	{
	$Area_01=odbc_result($result_Area,"Area_01");	
	$Area_02=odbc_result($result_Area,"Area_02");	
	$Area_03=odbc_result($result_Area,"Area_03");	
	$Area_04=odbc_result($result_Area,"Area_04");	
	$Area_05=odbc_result($result_Area,"Area_05");	
	}

$id = $Area_01;

while(!empty($id)){

     echo "moose<br>";
     //some sample code to check the loop works!

     if ($id == $Area_01){$id == $Area_02}
     elseif ($id == $Area_02){$id == $Area_03}
     elseif ($id == $Area_03){$id == $Area_04}
     elseif ($id == $Area_04){$id == $Area_05}
     else {$id == $Area_05}

}

 

So for example if fields Area_01, Area_02, Area_03 are populated and Area_04 is empty, I would expect to see:

 

moose

moose

moose

 

Instead I get the following error message.

 

Error:

Parse error: parse error, unexpected '}' in D:\Intranet v3\Sales\home.php

 

Can anyone see where I'm going wrong?

Link to comment
https://forums.phpfreaks.com/topic/67019-solved-error-in-code-while-loop/
Share on other sites

Cheers MadTechie,

I obviously need to catch up on some sleep!

 

Here's my revised and working While Loop in case anyone else was looking!

 

while(!empty($id)){

echo "- $id<br>";

if ($id == $Area_01){$id = $Area_02;}
elseif ($id == $Area_02){$id = $Area_03;}
elseif ($id == $Area_03){$id = $Area_04;}
elseif ($id == $Area_04){$id = $Area_05;}
elseif ($id == $Area_05){$id = 'NULL';}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.