newphpcoder Posted June 18, 2012 Share Posted June 18, 2012 Hi.. Now, I have select query with if condition, that if null the table data <td> will have background-color : red here is my code: $sql = "SELECT DISTINCT IF(ISNULL(a.LOG_IN), 'rdc', '') AS LOGIN_CLASS, IF(ISNULL(a.LOG_OUT), 'rdc', '') AS LOGOUT_CLASS, a.EMP_ID, a.LOG_IN, a.LOG_OUT, CONCAT(LNAME, ',' , FNAME, ' ', MI, '.') AS FULLNAME FROM hrdb.attendance AS a JOIN hris.employment em ON (a.EMP_ID = em.EMP_NO AND em.STATUS = 'Reg Operatives') JOIN hris.personal AS p ON p.EMP_ID = em.EMP_ID WHERE ATTENDANCE_DATE BETWEEN '2012-06-01' AND '2012-06-15' OR ATTENDANCE_DATE = '0000-00-00' OR ISNULL(a.LOG_IN) OR ISNULL(a.LOG_OUT) ORDER BY FULLNAME, a.LOG_IN, a.LOG_OUT"; $DTR = $conn3->GetAll($sql); $smarty->assign('attendance', $DTR); .rdc {background-color:#ff0000;} {section name=att loop=$attendance} <table> <tr> <td colspan="2" class="{$attendance[att].LOGIN_CLASS}">{$attendance[att].LOG_IN}</td> <td colspan="2" class="{$attendance[att].LOGOUT_CLASS}">{$attendance[att].LOG_OUT}</td> {sectionelse} <tr><td colspan="1">No DATA</td></tr> {/section} Now.. I need to revise my select if condition, because now the LOG_IN and LOG_OUT has no possibilities to have NULL values but now It will have 0000-00-00 00:00:00 values. So I need to put background color if the LOG_IN is 0000-00-00 00:00:00 also with LOG_OUT. Thank you so much Link to comment https://forums.phpfreaks.com/topic/264357-need-help-in-using-if-condition-to-select-query/ Share on other sites More sharing options...
fenway Posted June 30, 2012 Share Posted June 30, 2012 First, I think your query doesn't work the way to you expect, since you're mixing AND and OR conditions without parentheses. Second, just change "ISNULL(LOG_IN)" to "LOG_IN=0". Link to comment https://forums.phpfreaks.com/topic/264357-need-help-in-using-if-condition-to-select-query/#findComment-1358156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.