初學者 問下PHP取出MYSQL資料,然後倒置順序

來源:互聯網
上載者:User
菜鳥 問下PHP取出MYSQL資料,然後倒置順序
mysql資料


php代碼:
$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(array("name"=>"IP流量","data"=>$ip_ip));
$data_ip = json_encode($data_ip);
$times_ip = json_encode($time_ip);
$times_ip = str_replace('2015-', '', $times_ip);


結果:
["01-25","01-25","01-24","01-23","01-22"]

[{"name":"IP\u6d41\u91cf","data":[12632220,12735020,127350,2213488,2348888]}]


想要的效果:
["01-22","01-23","01-24","01-25","01-26"]

[{"name":"IP\u6d41\u91cf","data":[2348888,2213488,127350,12735020,12632220]}]


說明: 就是相當於 把取出的最新5條資料,倒置過來。正常的取出來的5條最新資料是:5 4 3 2 1. 想要的是 1 2 3 4 5。 5 是最新的資料。

致謝!
------解決思路----------------------
id desc 改成 id asc 是不行的!
id desc 的本意是取最新資料,而 id asc 是取最舊的資料
要用 array_reverse 轉置數組
$data_ip = array(array("name"=>"IP流量","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);
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.