我想按日期顺序从 mysql 数据库获取数据,只从数据库返回 1 条记录, 如果有人今天注册,并且在我希望它带来第一个人的详细信息而不是第二个人的几分钟后注册
我应该使用这两种方法中的哪一种?
mysqli_query($conn,"select * fromprovided_user where status = '1' AND plan = '{$_SESSION['plan']}' ORDER By date_of_ph ASC LIMIT 1");
或
mysqli_query($conn,"select * from provided_user where status = '1' AND plan = '{$_SESSION['plan']}' ORDER By date_of_ph DESC LIMIT 1");
稍微解释一下会有所帮助
最佳答案
mysqli_query($conn,"select * from provided_user where status = '1' AND plan = '{$_SESSION['plan']}' ORDER By date_of_ph ASC LIMIT 1");
此方法适用于您当前的情况,因为它会按升序获取您作为参数给出的日期的所有记录,因此第一个记录将首先返回,稍后添加的记录。通过将其限制为 1,您可以确保查询只会返回当天的第一条记录。 祝你好运
关于php - mysql中根据日期对获取的数据进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42967845/