gpt4 book ai didi

php - listView中按日期显示数据

转载 作者:行者123 更新时间:2023-11-30 01:36:06 24 4
gpt4 key购买 nike

这是我的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 显示在底部?谢谢

最佳答案

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

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

关于php - listView中按日期显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com