Page 1 of 1

Need help with elseif statement

Posted: Fri Sep 10, 2010 1:16 pm
by prototype18
My Code is below. For some reason the field STATUS_BYTE has a value of "F", but when the program goes through the elseif statements it executes through the "" but once it gets to the "C" it stops and displays that as the output... It should recgonize "F" as the correct choice but doesn't.. Any help would be appreciated.

Code: Select all

<?
		if($myrowvia2['STATUS_BYTE'] = "")
		{
		?>
			<TD bgcolor=<?=$chgc?> width="20%"><?=$fontcall3?><? echo 'OPEN' ?></TD>
		<?
		}
		elseif($myrowvia2['STATUS_BYTE'] = "C")
		{
		?>
			<TD bgcolor=<?=$chgc?> width="20%"><?=$fontcall3?><? echo 'CANCELLED' ?></TD>
		<?
		}
		elseif($myrowvia2['STATUS_BYTE'] = "F")
		{
		?>
			<TD bgcolor=<?=$chgc?> width="20%"><?=$fontcall3?><? echo 'COd' ?></TD>
		<?
		}
		elseif($myrowvia2['STATUS_BYTE'] = "P")
		{
		?>
			<TD bgcolor=<?=$chgc?> width="20%"><?=$fontcall?><? echo 'PROBLEM' ?></TD>
			<?
		}
		elseif($myrowvia2['STATUS_BYTE'] = "R")
		{
		?>
			<TD bgcolor=<?=$chgc?> width="20%"><?=$fontcall?><? echo 'REOPENED' ?></TD>
			<?
		}
		elseif($myrowvia2['STATUS_BYTE'] = "S")
		{
		?>
			<TD bgcolor=<?=$chgc?> width="20%"><?=$fontcall?><? echo 'CLOSED' ?></TD>
					<?
		}
		?> 

Re: Need help with elseif statement

Posted: Fri Sep 10, 2010 2:15 pm
by AbraCadaver
==

Re: Need help with elseif statement

Posted: Fri Sep 10, 2010 2:22 pm
by prototype18
THANK YOU!

Re: Need help with elseif statement

Posted: Fri Sep 10, 2010 2:26 pm
by AbraCadaver
prototype18 wrote:THANK YOU!
You're welcome. Also, there are shorter ways to do it. A switch would be one, or a lookup array:

Code: Select all

$mappings = array('C'=>'CANCELLED', 'F'=>'COd', 'P'=>'PROBLEM', 'R'=>'REOPENED', 'S'=>'CLOSED');

if(isset($mappings[$myrowvia2['STATUS_BYTE']])) {
	$status = $mappings[$myrowvia2['STATUS_BYTE']];
} else {
	$status = 'OPEN';
}
echo "<TD bgcolor=\"$chgc\" width=\"20%\">$fontcall3 $status</TD>";