thinkphp框架条件查询数据库,查询时间段代码怎么写?
2022-07-28 14:14:58
180
{{single.collect_count}}


先来看看判断语句

标签含义
eq或者 equal等于
neq 或者notequal不等于
gt大于
egt大于等于
lt小于
elt小于等于
heq恒等于
nheq不恒等于

比如现在我们想查询一条没有过期的优惠卷

首先我们要先得到现在的时间$time作为判断根据

其次数据表中要有优惠卷到期的日期coupon_endtime

然后在数据表中查询代码可以这样写

$coupon=M('coupon');//M()函数是初始数据库中的数据表对象$where['coupon-endtime']=array('egt',$time);$result=$coupon->where($where)->select();$this->ajaxReturn($result);

也可以这样写

用来查询一个时间段

$endtime='9000-00-00 00:00:00';$where['coupon_time']=array('between',$time,$endtime));//$time是时间段的开始时间,endtime是时间段的结束时间

一般情况下判断条件where这样写

$where[ '字段名 ' ]=array('判断语句','判断条件' ),判断语句就是上面的表格内容;

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}