Php query mysql multi-condition judgment output display

Source: Internet
Author: User

Php query mysql multi-condition judgment output display

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.

Figure 1 database structure:

Figure 2 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:

------ 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 ['B']}";

Else

Echo "{$ row ['B']}";

Echo "{$ row ['person ']} {$ row ['dtime']}";

Correct

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.