Hello all, I have a little question that im hoping someone can lead me in the right direction to answer. I have a PHP script that pulls information from a database and displays it. Simple. What I would like to do NOW, is based on a field value integer (0 - 3) I would like to make the field's different colors.
I will post my code below, for some perusal. Just some quick facts...
The name of the field is "VarCustom03"
The numbers are 0, 1, 2, 3. Each with a different color.
I was thinking of doing something like this...
<?php if ($x_VarCustom03 = 0) {?>
<tr bgcolor="#FFFFCC">
<?php } else if ($x_VarCustom03 = 1) {?>
<tr bgcolor="#66FF33">
<?php } else if ($x_VarCustom03 = 2) {?>
<tr bgcolor="#FFFF33">
<?php } else if ($x_VarCustom03 = 3) {?>
<tr bgcolor="red">
<?php } else { ?>
<tr bgcolor="#FFFFCC">
<?php } ?>
But that does not seem to work. The first "match" that the PHP code finds it makes all the other fields that color. In this case green. Could someone help?!
The snipplet is here..
<--SNIP-->
<?php
$recCount = $startRec - 1;
@mysql_data_seek($rs, $recCount);
while (($row = mysql_fetch_assoc($rs)) && ($recCount < $stopRec))
{
$recCount++;
if (intval($recCount) >= intval($startRec))
{
//set row color
$bgcolor="#FFFFFF";
?>
<?php
$x_MsgUnique = $row["MsgUnique"];
$x_MsgDate = $row["MsgDate"];
$x_MsgTime = $row["MsgTime"];
$x_MsgPriority = $row["MsgPriority"];
$x_MsgHostname = $row["MsgHostname"];
$x_MsgText = $row["MsgText"];
?>
<tr bgcolor="<?php echo $bgcolor ?>">
<td><font size="-1">
<b><?php echo $x_MsgUnique ?></b>
</font></td>
<td><font size="-1">
<?php echo $x_MsgDate ?>
</font></td>
<td><font size="-1">
<?php echo $x_MsgTime ?>
</font></td>
<td><font size="-1">
<?php echo $x_MsgPriority ?>
</font></td>
<td><font size="-1">
<a href="telnet://<?php echo $x_MsgHostname ?>"><?php echo $x_MsgHostname ?></a>
</font></td>
<td><font size="-1">
<?php echo str_replace(chr(10),"<br>",$x_MsgText . "") ?>
</font></td>
<td><a href="<?php
if ($row["MsgUnique"] != NULL)
{ echo "mantic_msgsview.php?key=".urlencode($row["MsgUnique"]); }
else
{ echo "javascript:alert('Invalid Record! Key is null.');"; }
?>"><img src="images/view.gif" alt="View" width="16" height="16" border="0"></a></td>
<td><a href="<?php
if ($row["MsgUnique"] != NULL)
{ echo "mantic_msgsedit.php?key=".urlencode($row["MsgUnique"]); }
else
{ echo "javascript:alert('Invalid Record! Key is null.');"; }
?>"><img src="images/edit.gif" alt="Edit" width="16" height="16" border="0"></a></td>
</tr>