thinkphp6 where查询时候出现字段对比字段处理方法
2022-11-24 11:10:29
189
{{single.collect_count}}

这个有thinkphp官方其实给出了方法,那就是->where("字段1 = 字段2")

而使用->where(["字段一","=","字段二"])是不行的字段二会自动过滤成字符串

还有一种方法:修改查询model具体没有尝试随便敲着写着试试看吧

循环查询条件,值不为数组增加一个where

例如条件$where =[['字段1','=',1],"字段一 = 字段二"];$result=$this->alias('a');$wherestring="";$map=[];foreach ($where as $val){if(is_array($val)){$map[]=$val;}else{$wherestring[]=$val;}}$result=$result->where($map);foreach($wherestring as $val){$result=$result->where($val);}$result=$result->select();

以上代码自己优化,$map可去掉,unset就好在array_values(),最后一个循可外面加一个判断

回帖
全部回帖({{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 ? '加载中...' : '查看更多评论'}}