We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,445 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

changing color background

i cant seem to solve this.

how do i change the cell background color using php?

this is what i got;

<tr>
<td ><span class="style2">1</span></td>
<td >PERAK IP-F002</td>
<td bgcolor=<? if($a1==1) echo "#00ff00"; else echo "#ff0000"; ?>>&nbsp;</td>
<td bgcolor=<? if($a2==1) echo "#FF0000"; else echo "#00FF00"; ?>>&nbsp;</td>
<td bgcolor=<? if($a3==1) echo "#00ff00"; else echo "#ff0000"; ?>>&nbsp;</td>
</tr>
<tr>

is this correct?

3
Contributors
2
Replies
2 Hours
Discussion Span
2 Years Ago
Last Updated
3
Views
fadliraihana
Newbie Poster
3 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Try this

<tr>
<td ><span class="style2">1</span></td>
<td >PERAK IP-F002</td>
<td style="background-color:<?php if($a1==1) echo "#00FF00"; else echo "#FF0000"; ?>">&nbsp;</td>
<td style="background-color:<?php if($a2==1) echo "#FF0000"; else echo "#00FF00"; ?>">&nbsp;</td>
<td style="background-color:<?php if($a3==1) echo "#00FF00"; else echo "#FF0000"; ?>">&nbsp;</td>
</tr>
adkhan
Newbie Poster
24 posts since Oct 2009
Reputation Points: 35
Solved Threads: 8
Skill Endorsements: 0

You can also use ternary operator for minimizing code.

<tr>
<td ><span class="style2">1</span></td>
<td >PERAK IP-F002</td>
<td style="background-color:<?=($a1==1)?('#00FF00'):('#FF0000');?>">&nbsp;</td>
<td style="background-color:<?=($a2==1)?('#FF0000'):('#00FF00');?>">&nbsp;</td>
<td style="background-color:<?=($a3==1)?('#00FF00'):('#FF0000');?>">&nbsp;</td>
</tr>
vibhaJ
Posting Shark
958 posts since Apr 2010
Reputation Points: 161
Solved Threads: 190
Skill Endorsements: 3

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0659 seconds using 2.8MB