Forum Moderators: coopster

Message Too Old, No Replies

IF ELSE in an Array

         

paseo

5:16 pm on Feb 28, 2008 (gmt 0)

10+ Year Member



Hi,

I have a fairly basic code snippet below that will fetch data from MySQL and place it into an array. From this array, I am displaying the results in a table with 1 row for each row fetched. What i want is to somehow incorporate an IF ELSE statement to change the font color of the status field. Example, if the status is Confirmed, then i want the font color to be green. If it is anything else, I want it to be red. I have tried including and IF statement from within the ECHO command below but I just cant seem to get the proper syntax. Can anybody assist? I have included the snippet im using below. THANKS!

<?php

while($abc=mysql_fetch_array($xyz)){

echo "
<tr>
<td>{$abc['month']}</td>
<td>{$abc['day']}</td>
<td>{$abc['year']}</td>
<td>{$abc['time']}</td>
<td>{$abc['type']}</td>
<td>{$abc['status']}</td>
</tr>";

}

?>

Vis3R

5:55 pm on Feb 28, 2008 (gmt 0)

10+ Year Member



should work, didn't test tho
if you don't like the one-line-if you can change it to the normal type..

<?php

while($abc=mysql_fetch_array($xyz)){

echo "
<tr".($abc['status']=='Confirmed' ? ' style="color:#00FF00"' : ' style="color:#FF0000"').">
<td>{$abc['month']}</td>
<td>{$abc['day']}</td>
<td>{$abc['year']}</td>
<td>{$abc['time']}</td>
<td>{$abc['type']}</td>
<td>{$abc['status']}</td>
</tr>";

}

?>

[edited by: Vis3R at 5:56 pm (utc) on Feb. 28, 2008]

paseo

6:56 pm on Feb 28, 2008 (gmt 0)

10+ Year Member



Had to modify it a little bit but it was EXACTLY what i needed. THANKS!