Jump to content

mysql if statment


trilbyfish

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/98864-mysql-if-statment/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/98864-mysql-if-statment/#findComment-506295
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.