【问题标题】:Display data according to date in listView在 listView 中根据日期显示数据
【发布时间】:2016-01-30 08:03:15
【问题描述】:

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

<?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 显示在底部?谢谢

【问题讨论】:

  • 只需在SQLselect * from information WHERE name= '". $name."' and MONTH(date) = '".$month."' ORDER BY date"中添加order by子句@
  • @TahTatsumoto 谢谢!!但现在最高的是2016-01-02。如何按降序显示日期?

标签: php android date listview


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-10
    相关资源
    最近更新 更多