在thinkphp中,distinct()方法用于去除重復的值,能夠返回唯一不同的值,distinct方法的參數(shù)是一個布爾值,語法為“$Model->distinct(布爾值參數(shù))->field('name')->select();”。
本文操作環(huán)境:Windows10系統(tǒng)、ThinkPHP3.2版、Dell G3電腦。
thinkphp中distinct的用法是什么
TP中distinct()的用處主要是去除重復的值
DISTINCT 方法用于返回唯一不同的值 。
$Model->distinct(true)->field('name')->select();
生成的SQL語句是:
SELECT DISTINCT name FROM think_user
示例如下:
顯示的是這樣的
在加入distinct的話:
顯示結(jié)果為
下面為貼出來的代碼
$offernum = M('offer')->distinct(true)->where('order_id='.$order_id)->field('user_id,number')->select(); dump($offernum);
推薦學習:《PHP視頻教程》