Page 1 of 1

changing <td> color in php

Posted: Fri Oct 09, 2009 8:29 pm
by edawson003
Trying to change a table's <td> with a conditional php statement. This didn't work any thoughts?

Code: Select all

<td width=10><img src="../images/spacer10.gif" width="10" height="10[color=#0000FF]"><? 
if(($weightdisplay - $weightdisplay2) < 0) {
$weighttbl = "#ECA98E";
}
?>[/color]                </td>
                  <td width=411 align=center bgcolor[color=#0000FF]="<?php echo $weighttbl; ?>" />[/color]

Re: changing <td> color in php

Posted: Fri Oct 09, 2009 9:00 pm
by JNettles
What are the values for $weightdisplay and $weightdisplay2? Because if they're greater than 0........... then your echo won't produce anything.

Re: changing <td> color in php

Posted: Fri Oct 09, 2009 9:37 pm
by edawson003
No, there's actually, a lot more to it. Plus, I found a round about way to change the color with the cell. Probably not the best way to implement. Quick and nasty, but it works.

Code: Select all

 
 
<? 
if(($weightdisplay - $weightdisplay2) < 0) {
echo "<TABLE width=411 bgcolor=#9EDF94><tr><td align=center>";
echo "<span class=pgreen>MESSAGE 1 ";
echo round(((($weightdisplay) - ($weightdisplay2))*-1),1); 
echo " </span></td></tr></TABLE>";
}
elseif(($weightdisplay - $weightdisplay2) > 0 && $weightdisplay2 != NULL) {
echo "<TABLE width=411 bgcolor=#FF8585><tr><td align=center>";
echo "<p>MESSAGE 2 ";
echo round((($weightdisplay) - ($weightdisplay2)),1); 
echo " </span></td></tr></TABLE>";
}
elseif(($weightdisplay - $weightdisplay2) == 0 && $weightdisplay != NULL && $weightdisplay2 != NULL) {
echo "<TABLE width=411 bgcolor=#E9E9E9><tr><td align=center>";
echo "<p>MESSAGE 3</p>";
echo "</td></tr></TABLE>";
}
elseif($weightdisplay == NULL || $weightdisplay2 == NULL) {
echo "<TABLE width=411 bgcolor=#ABABAB><tr><td align=center bgcolor=#FFFFFF>";
echo "<p>MESSAGE 4</p>";
echo "</td></tr></TABLE>";
}
?>
 
 
All that is nested with a <td width=411> of another table. Liek I said, it works! :twisted:

Re: changing <td> color in php

Posted: Fri Oct 09, 2009 9:43 pm
by Griven
Are you just trying to alternate the row colors of the table?

Re: changing <td> color in php

Posted: Sat Oct 10, 2009 12:49 am
by edawson003
No, not in this instance; however, I am interested in being able to do that for another part of my site.