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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.