Need help with elseif statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prototype18
Forum Commoner
Posts: 25
Joined: Wed Aug 18, 2010 9:52 am

Need help with elseif statement

Post 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>
					<?
		}
		?> 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need help with elseif statement

Post by AbraCadaver »

==
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
prototype18
Forum Commoner
Posts: 25
Joined: Wed Aug 18, 2010 9:52 am

Re: Need help with elseif statement

Post by prototype18 »

THANK YOU!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need help with elseif statement

Post 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>";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply