Rookie ask PHP to remove MySQL data, and then inverted order

Source: Internet
Author: User
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
  • 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.