thinkphp中distinct的用法是什么
2022-11-24 11:02:51
155
{{single.collect_count}}

在thinkphp中,distinct()方法用于去除重复的值,能够返回唯一不同的值,distinct方法的参数是一个布尔值,语法为“$Model->distinct(布尔值参数)->field('name')->select();”。

php入门到就业线上直播课:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

本文操作环境:Windows10系统、ThinkPHP5版、Dell G3电脑。

thinkphp中distinct的用法是什么

TP中distinct()的用处主要是去除重复的值

DISTINCT 方法用于返回唯一不同的值 。

$Model->distinct(true)->field('name')->select();
登录后复制

生成的SQL语句是:

SELECT DISTINCT name FROM think_user
登录后复制

示例如下:

111.png

显示的是这样的

222.png

在加入distinct的话:

333.png

显示结果为

444.png

下面为贴出来的代码

$offernum = M('offer')->distinct(true)->where('order_id='.$order_id)->field('user_id,number')->select();dump($offernum);
登录后复制

推荐学习:《PHP视频教程

以上就是thinkphp中distinct的用法是什么的详细内容,更多请关注php中文网其它相关文章!

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