PHP query MySQL multi-conditional judgment output display

Source: Internet
Author: User

PHP query MySQL multiple condition judgment output display

Background:

Query each field value output from MySQL and display the criteria field values in red font.

Conditions:

1.syntime is less than the current week before the words show red.

2.A field is "None", the display is red.

3.B field is "None", the display is red.

Figure A database structure:

Figure Two database field values:

My Code: (I only met the first condition, the other two conditions do not know how to write)

$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 your aunt to improve the code. To be able to satisfy three conditions at the same time, and the correct output, the red display where the red. 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 the

Related Article

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.