Php query mysql multi-condition judgment output background:
Query the output of each field value from mysql and display the field values that meet the condition in red according to the condition.
Condition:
1. if syntime is less than the previous week, the syntime is red.
2. if field A is "none", it is red.
3. if the field B is "none", it is red.
Database structure:
Database field values:
My code: (I only met the first condition, but I don't know how to write the other two conditions)
$ SQL = "select username, onoff, intime, syntime, device, a, B, person, dtime from cdmobile order by username desc ";
$ Rst = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ rst )){
$ Nowtime = strtotime ('+ 7 Day ');
$ Syntime = strtotime ($ row ['syntime']);
If ($ nowtime >=$ syntime ){
Echo"{$ Row ['username']}{$ Row ['onoff']}{$ Row ['intime']}{$ Row ['syntime']}{$ Row ['device']}>{$ Row ['A']}{$ Row ['B']}{$ Row ['person ']}{$ Row ['dtime']}";
}
Else
Echo"{$ Row ['username']}{$ Row ['onoff']}{$ Row ['intime']}{$ Row ['syntime']}{$ Row ['device']}{$ Row ['A']}{$ Row ['B']}{$ Row ['person ']}{$ Row ['dtime']}";
}
Please help me complete the code. If three conditions are met at the same time and the output is correct, the red area is displayed. The following are the current results:
Reply to discussion (solution)
Echo"{$ Row ['username']}{$ Row ['onoff']}{$ Row ['intime']}"; If ($ nowtime >=$ syntime) echo"{$ Row ['syntime']}"; Else echo"{$ Row ['syntime']}"; Echo"{$ Row ['device']}"; If ($ row ['A'] =" none ") echo"{$ Row ['A']}"; Else echo"{$ Row ['A']}"; If ($ row ['B' =" none "]) echo"{$ Row ['A']}"; Else echo"{$ Row ['B']}"; Echo"{$ Row ['person ']}{$ Row ['dtime']}";
Echo"{$ Row ['username']}{$ Row ['onoff']}{$ Row ['intime']}"; If ($ nowtime >=$ syntime) echo"{$ Row ['syntime']}"; Else echo"{$ Row ['syntime']}"; Echo"{$ Row ['device']}"; If ($ row ['A'] =" none ") echo"{$ Row ['A']}"; Else echo"{$ Row ['A']}"; If ($ row ['B'] =" none ") echo"{$ Row ['B']}"; Else echo"{$ Row ['B']}"; Echo"{$ Row ['person ']}{$ Row ['dtime']}";
Correct
No, it's wrong.
Correct. Thank you. I added more brackets and added them. Thank you!
$ Syntime_style = $ nowtime >=$ syntime? 'Styly = "color: red "':'';
$ A_style = $ row ['A'] = 'none '? 'Styly = "color: red "':'';
$ B _style = $ row ['B'] = 'none '? 'Styly = "color: red "':'';
Echo"{$ Row ['username']}{$ Row ['onoff']}{$ Row ['intime']}{$ Row ['syntime']}{$ Row ['device']}{$ Row ['A']}{$ Row ['B']}{$ Row ['person ']}{$ Row ['dtime']}";