在listView

时间:2016-01-30 08:03:16

标签: php android date listview

这是我的 Activtiy A ,其中所有数据都从MySQL检索到listView。 (根据给定的名称和月份选择数据)

enter image description here

<?php
  define('HOST','127.0.0.1:3307');
  define('USER','root');
  define('PASS','');
  define('DB','androiddb');

  $con = mysqli_connect(HOST,USER,PASS,DB) or die('unable to connect');

  $name = $_GET['name'];

  $month = $_GET['month'];

 $sql = "select * from information WHERE name= '". $name."' and MONTH(date) = '".$month."'";

  $res = mysqli_query($con,$sql);

  $result=array();


  while($row=mysqli_fetch_array($res)){
      array_push($result,array('id'=>$row[0],'name'=>$row[1],'weather'=>$row[2],'date'=>$row[3],'status'=>$row[4],
      'time_in'=>$row[5], 'time_out'=>$row[6]));
  }

 echo (json_encode(array("result"=>$result)));

mysqli_close($con);

?>

如何根据日期显示数据?我希望2016-01-30位于顶部,2016-01-02显示在最低位置?感谢

1 个答案:

答案 0 :(得分:1)

我的评论是按升序排序。如果你想降序,只需将其改为

即可
"select * from information WHERE name= '". $name."' and MONTH(date) = '".$month."' ORDER BY date DESC"