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];