mdemetri2 Posted October 12, 2011 Share Posted October 12, 2011 Hi I have a table that populated by a recordset, and wondered whether is was possible to make a row background colour = red where a particular cell = some text? I have been searching around and not managed to find anything of use. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/ Share on other sites More sharing options...
WebStyles Posted October 12, 2011 Share Posted October 12, 2011 Anything is possible! can you post your code please? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278548 Share on other sites More sharing options...
mdemetri2 Posted October 12, 2011 Author Share Posted October 12, 2011 I dont have any code, as I have not attempted to do it. If I had anything it would just be a table populated by a recordset..... Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278549 Share on other sites More sharing options...
WebStyles Posted October 12, 2011 Share Posted October 12, 2011 I have a table that populated by a recordset where's the code for that? Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278551 Share on other sites More sharing options...
ManiacDan Posted October 12, 2011 Share Posted October 12, 2011 echo "<td style='background-color: " . ( $val < 0 ? 'red' : 'white' ) . ";'>{$val}</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278559 Share on other sites More sharing options...
mdemetri2 Posted October 12, 2011 Author Share Posted October 12, 2011 Thanks for the code, I have not had a go as yet, but I'm going to try adding it to the following table code: <table width="728" border="1"> <tr> <td>id</td> <td>value</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['id']; ?></td> <td><?php echo $row_Recordset1['Value']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278605 Share on other sites More sharing options...
ManiacDan Posted October 12, 2011 Share Posted October 12, 2011 The answer was there for two hours before you posted Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278614 Share on other sites More sharing options...
mdemetri2 Posted October 13, 2011 Author Share Posted October 13, 2011 It may have been, but I'm not constantly connected to the internet or on this forum. I will attempt to use your code which you helpfully posted to make it do what I want. Bare with me, my php knowledge is limited. Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278887 Share on other sites More sharing options...
mdemetri2 Posted October 13, 2011 Author Share Posted October 13, 2011 hi, ok, made some inroads, but the formatting comes out off, in that the columns dont align for some reason, but I made code look like this and it works: <table width="468" border="1"> <tr> <td width="287">id</td> <td width="165">value</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['id']; ?></td> <td><?php echo "<td style='background-color: " . ( $row_Recordset1['Value'] == 1 ? 'red' : 'white' ) . ";'>{$row_Recordset1['Value']}</td>"; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> Can anyone suggest how to make the table align? Also, what about multiple criteria e.g. 1 = red, 2 = blue, 3 = green etc etc.....? [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278905 Share on other sites More sharing options...
ManiacDan Posted October 13, 2011 Share Posted October 13, 2011 You're printing a TD cell inside a TD cell. Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1278972 Share on other sites More sharing options...
mdemetri2 Posted October 14, 2011 Author Share Posted October 14, 2011 ok, thanks, figured it out. Apprecuated. Quote Link to comment https://forums.phpfreaks.com/topic/248961-conditional-format-cell-colour-on-table/#findComment-1279317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.