trilbyfish Posted March 31, 2008 Share Posted March 31, 2008 when retrieving values from an sql table, is it possible to use an if statment to colour the cells based on what they contain eg. if empty set cell background colour to green else set background colour to red the background colour would probably be set using html thanks in advance Quote Link to comment Share on other sites More sharing options...
mwasif Posted March 31, 2008 Share Posted March 31, 2008 You can use both IF and CASE statements. It is better to handle such kind of things in PHP or whatever language you are using. Quote Link to comment Share on other sites More sharing options...
aschk Posted April 1, 2008 Share Posted April 1, 2008 Sounds more like something that PHP could do for you. However, you could generate an additional column in your SQL resultset that has the colour of the background (based on value). SELECT IF(STRCMP('',TRIM(col1)),'green','red') as 'colour' FROM <table name here> Obviously put your table name in there, and change the "col1" to whaever colomn you're basing your result on. Once you have this in your resultset you can then use the "colour" when you iterate through your dataset. All you're doing is abstracting the same IF clause into a different layer really. Quote Link to comment 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.