How PHP takes the maximum value from the query results and assigns the style

Source: Internet
Author: User
The values for the A,b,time three fields are now removed from the database x table.
If the value of a in the query results is xiaoming, the background color is #96 and the font color is white.
You now need to add a condition that if time (type DateTime) is the closest you have now, the font for all the fields in that row is changed to red.
How do I set up $time_style.
At the same time meet the above two conditions.
The following code satisfies the first condition:

$sql = "Select A,b,time from X";
$rst = mysql_query ($sql);
while ($row =mysql_fetch_assoc ($rst)) {
$VIP _style = $row [' A ']== "Xiao Ming"? ' style= ' background-color: #096; color:white; "': ';
echo "{$row [' a ']}{$row [' B ']}{$row [' Time ']}";}


Reply to discussion (solution)

You can $sql = "Select A,b,time from X order by time Desc;
Take the first piece of data; If this data satisfies a== xiaoming, it turns red. That would not satisfy two conditions.

You must calculate the time difference before you know who is the smallest
You want to do it over and over again, you can't do it.

You can $sql = "Select A,b,time from X order by time Desc;
Take the first piece of data; If this data satisfies a== xiaoming, it turns red. That would not satisfy two conditions.



How to take it?

You must calculate the time difference before you know who is the smallest
You want to do it over and over again, you can't do it.



Or how do I take the maximum time value for all the fields in that row for the style setting?


You can $sql = "Select A,b,time from X order by time Desc;
Take the first piece of data; If this data satisfies a== xiaoming, it turns red. That would not satisfy two conditions.



How to take it?


$row =mysql_fetch_row[$sql];



You can $sql = "Select A,b,time from X order by time Desc;
Take the first piece of data; If this data satisfies a== xiaoming, it turns red. That would not satisfy two conditions.



How to take it?


$row =mysql_fetch_row[$sql];





You can $sql = "Select A,b,time from X order by time Desc;
Take the first piece of data; If this data satisfies a== xiaoming, it turns red. That would not satisfy two conditions.



How to take it?


$row =mysql_fetch_row[$sql];


Sorry, it should be.
$result =mysql_query ($sql);
$row =mysql_fetch_row[$result];
  • 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.