Home > Backend Development > PHP Tutorial > PHP获取查询数据中最早的时间和最晚时间怎么写这样不知对不对

PHP获取查询数据中最早的时间和最晚时间怎么写这样不知对不对

WBOY
Release: 2016-06-23 13:23:44
Original
997 people have browsed it


PHP获取查询数据中最早的时间和最晚时间怎么写??这样不知对不对
如下貌似运行正常啊,但是感觉并不是这样的写法吧

$EarlyTime=mysql_result(mysql_query("select min(Time) from user where General=1 and UserID='".$row['DatID']."'",$conn),0);$LatestTime=mysql_result(mysql_query("select max(Time) from user where General=1 and UserID='".$row['DatID']."'",$conn),0);
Copy after login


而且我感觉这样的执行效率太慢了。。。。索引了已经  还这样慢  受不鸟


请大神给个标准的获取数据库中最早时间和最后时间的方法吧

感激不尽!坐等高手!十分感谢!


回复讨论(解决方案)

在 Time、General、UserID 上都有索引吗?

两句应该合在一起写
list($EarlyTime, $LatestTime) = mysql_fetch_row(mysql_query("select min(Time), max(Time) from user where General=1 and UserID='".$row['DatID']."'"));

无以言表啊!楼上你收下我的掌声吧!

太感谢了!一下子优化了近一半!

膜拜啊。。大神!~

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template