How does PHP obtain the maximum value in the query result and assign the style

Source: Internet
Author: User
How does PHP obtain the maximum value in the query result and grant the style to retrieve the values of fields a, B, and time from database X.
If the value of a in the query result is Xiaoming, the background color is #96 and the font color is white.
Now you need to add a condition. if time (datetime type) is the closest time, the font of all fields in the row turns red.
How can I set $ time_style.
Both of the preceding conditions are met.
The following code meets 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 piece of data meets a = James, it turns red. In this way, the two conditions are not met.

You must calculate the time difference before you can know who is the minimum.
You can't do it if you want to do it all over again.

You CAN $ SQL = "select a, B, time from X order by time desc;
Take the first piece of data. if this piece of data meets a = James, it turns red. In this way, the two conditions are not met.



How to get it?

You must calculate the time difference before you can know who is the minimum.
You can't do it if you want to do it all over again.



Or how can I retrieve all fields in the row with the maximum time value and set the style?


You CAN $ SQL = "select a, B, time from X order by time desc;
Take the first piece of data. if this piece of data meets a = James, it turns red. In this way, the two conditions are not met.



How to get 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 piece of data meets a = James, it turns red. In this way, the two conditions are not met.



How to get 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 piece of data meets a = James, it turns red. In this way, the two conditions are not met.



How to get 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.