![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
thinkPHP查数据库
零零零jiawei
这个作者很懒,什么都没留下…
展开
-
结束日期大于现在日期 或 某日期在两个日期之间
$where['mgiftorder.fddDateE'] = array('elt',date('Y-m-d H:i:s')); //elt是小于等于$where['mgiftorder.fddDateE'] = array('egt',date('Y-m-d H:i:s')); //egt是大于等于$where['fdlSupplyID'] - array('neq',$s...翻译 2018-04-16 15:31:35 · 626 阅读 · 0 评论 -
在field里面做判断
$field=[ "mvoucherorder.ID", "ifnull(ifnull(acard.fdcName,acard.fdcNick),CONCAT(acard.fdcNo,'(未关注会员)')) as fdcNick", "mvoucherorder.fddDateU", "acard.fdcImage"]; $data ...原创 2018-05-05 09:36:43 · 1272 阅读 · 0 评论 -
用eleme框架选出来的日期是object,需要转换格式才能添加进数据库
if(typeof(this.editForm.fddDateE)=='object'){ this.editForm.fddDateE = this.$util.formatDate.format(this.editForm.fddDateE,'yyyy-MM-dd') //转出2017-12-12 this.editForm.fddDateE = this...原创 2018-05-05 09:44:40 · 235 阅读 · 0 评论 -
ID等于3或4或5
$where=[ "_string"=>"(ID=3 or id=4 or id=5)", "fdbStop"=>0, ]; 或者 $where=[ "_string"=>"(id>5)", "fdbStop"=>0, ]; 或者 $where['mVou...原创 2018-05-07 08:35:25 · 414 阅读 · 0 评论 -
计算某字段数值的总和
$data = M('mfilmgivesupply')->where($where)->sum('fdiSendS');原创 2018-05-08 16:06:44 · 2006 阅读 · 0 评论 -
同时查出两个表的数据然后按careat_ed输出
//获取客户的代金券券列表,在唯佳的model里面的Marketing.php中 public function getVoucherOrder($shopCardID,$fdlCardID,$type,$page,$num){ $page =($page-1)*$num; $sCardID=$fdlCardID; if ($type == 'unu...原创 2018-05-08 16:07:14 · 136 阅读 · 0 评论 -
某字段的数据有相同只拿出其中一条数据(distinct)
方式一: $data = $Model->distinct(true)->field('name')->select(); //只能查出name字段,且把name一样的都去除了 $data = M('signintimes')->field(['distinct fddModifyTime'])->select(); ...原创 2018-05-08 16:07:35 · 1548 阅读 · 0 评论 -
某字段为null,某字段不为null
为null: $where['mselgroupset.fdiIndex']=array( 'exp', 'is null' );不为null: $where['mselgroupset.fdiIndex']=array( 'exp', 'is not null' );原创 2018-06-27 09:36:27 · 459 阅读 · 0 评论 -
只查出一个字段
M('mluck') -> where(['ID' => $v['fdlSrcID']]) -> getField('fdcImage');原创 2018-09-26 16:30:31 · 195 阅读 · 0 评论 -
当前时间往前退2天
$begin =date("Y-m-d",strtotime("-2 day")); //现在时间退2天$begin =date("Y-m-d H:i:s",strtotime("+2 hour")); //现在时间退2小时date("Y-m-d",strtotime("+1 month",strto原创 2018-04-17 15:01:00 · 276 阅读 · 0 评论 -
某值在两个数之间
$begin =date("Y-m-d",strtotime("-2 day"));$end = date('Y-m-d')." 23:59:59";$where['mvoucherorder.fddDateU']=array('BETWEEN',array($begin,$end));翻译 2018-04-16 15:44:43 · 342 阅读 · 0 评论 -
把多条数据放到一字段的写法
不能用left join了,这个一会变多条数据正确的写法是把一先查出来,在用ID循环查出多的数据放到一的某字段中栗子: public function voucherList ($supplyID){ $data = M('mvoucher') ->where(['fdlSupplyID'=> $supplyID]) ...翻译 2018-04-16 15:35:05 · 901 阅读 · 0 评论 -
查询数据库时条件是 或 的写法(且或)
或: if (!empty($kw)) { $map['mSupply.fdcName'] = ['like', '%' . $kw . '%']; $map['mVoucher.fdcName'] = ['like', '%' . $kw . '%']; $map['mVoucher.fdcTitle'] ...翻译 2018-04-16 15:36:01 · 5532 阅读 · 0 评论 -
条件是一个表里面的两个字段比较
$where['mvoucher.fddDate'] = array('egt',date('Y-m-d H:i:s'));$where['_string'] = 'fdnNum > fdnSell'; //这个就是或者 $where = ["fdlCardID"=>$cardid,"_string"=>"((fdiSta...翻译 2018-04-16 15:36:52 · 2161 阅读 · 0 评论 -
find() 和 select()
->select() //取多条数据,找出来的是数组->find() //只取一条数据,找出来的是json翻译 2018-04-16 15:38:37 · 1477 阅读 · 0 评论 -
某字段++
$data = M('mvoucher')->where(['ID'=> $voucherID])->setInc('fdnLook', 1); //+1 setDec('fdnLook', 1); //-1翻译 2018-04-16 15:39:25 · 127 阅读 · 0 评论 -
ID在某一个数组里,ID不在某个数组里
$where['ID'] = array('in',$arr); //ID在某一个数组里$where['ID'] =array('not in',$activeIDArr); //ID不在某个数组里翻译 2018-04-16 15:41:34 · 1420 阅读 · 0 评论 -
找某个字段的最大,最小值
$data = M('aprdtproxy')->field("max(fdiIndex) fdiIndex")->find(); //找最大翻译 2018-04-16 15:43:34 · 511 阅读 · 0 评论 -
子查询的写法
$fields = [ 'aprdt.ID', '(select 1 from aprdtproxy where aprdtproxy.fdlPrdtID=aprdt.ID and aprdtproxy.fdlShopID='.$fdlShopID.' LIMIT 1) fdbProxy', //如果条件符合的话,查出fdbProxy = 1];$data...翻译 2018-04-16 15:44:06 · 1038 阅读 · 0 评论 -
写条件时,LEFT JOIN的字段也要相等
'LEFT JOIN mluckrecord ON mvoucher.fdlLuckID = mluckrecord.fdlluckID AND mvsorder.fdlCardID = mluckrecord.fdlCardID'原创 2018-09-28 15:40:59 · 691 阅读 · 0 评论