MySQL Data
PHP Code:
$res _ip = mysql_query ("select * from IP order by ID DESC limit 0,5"), while ($row _ip = mysql_fetch_array ($res _ip)) { $ip _ip[] = intval ($row _ip[' IP "), $time _ip[] = date ($row _ip[' time ');} $data _ip = Array ("name" + "IP Traffic", "data" = $ip _ip)), $data _ip = Json_encode ($data _ip); $times _ip = Json_ Encode ($time _ip); $times _ip = Str_replace (' 2015-', ', $times _ip);
Results:
["01-25", "01-25", "01-24", "01-23", "01-22"]
[{"Name": "IP\U6D41\U91CF", "Data": [12632220,12735020,127350,2213488,2348888]}]
The desired effect:
["01-22", "01-23", "01-24", "01-25", "01-26"]
[{"Name": "IP\U6D41\U91CF", "Data": [2348888,2213488,127350,12735020,12632220]}]
Description: It is equivalent to take out the latest 5 data, inverted over. The 5 most recent data that is normally taken out are: 5 4 3 2 1. Want is 1 2 3 4 5. 5 is the latest data.
Thanks!
Reply to discussion (solution)
Sort by ID! Decrease or increment! You're supposed to be incrementing!
SELECT * from IP order by ID ASC limit 0,5?
ID DESC changed to ID ASC is no good!
ID DESC is intended to fetch the latest data, while the ID ASC is the oldest data
To transpose an array with Array_reverse
$data _ip = Array (Array ("Name" = "IP Traffic", "data" = Array_reverse ($ip _ip))), $data _ip = Json_encode ($data _ip); $ Times_ip = Json_encode (Array_reverse ($time _ip)), $times _ip = str_replace (' 2015-', ', $times _ip);
ID sort should be OK, is this supposed to be written in chronological order?
ID sort should be OK, is this supposed to be written in chronological order?
ASC does not work, take out the old data.
ID DESC changed to ID ASC is no good!
ID DESC is intended to fetch the latest data, while the ID ASC is the oldest data
To transpose an array with Array_reverse
$data _ip = Array (Array ("Name" = "IP Traffic", "data" = Array_reverse ($ip _ip))), $data _ip = Json_encode ($data _ip); $ Times_ip = Json_encode (Array_reverse ($time _ip)), $times _ip = str_replace (' 2015-', ', $times _ip);
The method of the owner is feasible, thank you