thinkphp? ?? ???? PHP ?????? ?????? ?? ??? ????? ??? ??? ??? ??? ?????. ??? ??? ?? ???? ???? ?? ???? ?? ??? ????. ??? thinkphp?? ??? ???? ???? ??? ?? ?????.
?? ???? ???? ??? ?? thinkphp? ?? ???? ?? ???????. thinkphp ?????? ???? ??? ???? ?? ??? ? ?? ?? ??? ?? ??? ?????. ?? ??? ???? ??? ?? ?? ???? ??? ??? ? ????.
$users?=?Db::name('user')->select();
? ??? ??????? user
???? ???? ???? ?????. ??? ???? ?? ???? ?? ???? ?? ???? ????? ??? ?? ???? user
表,并返回數(shù)據(jù)。但是,如果該表中有重復數(shù)據(jù),我們希望從結果中去除重復項該怎么辦呢?
thinkphp 提供了一個 distinct
方法,用于去除查詢結果中的重復項。使用方法非常簡單,我們只需要在查詢語句中添加 distinct
方法即可,如下所示:
$users?=?Db::name('user')->distinct(true)->select();
上面的代碼中,distinct(true)
方法表示打開去重標記。執(zhí)行 select()
方法時,結果集中所有列均將獨一無二地顯示。
除了 distinct
方法之外,thinkphp 中還提供了另外一個方法來去除查詢結果中的重復項,即 group
方法。使用 group
方法,我們可以指定一個字段作為分組依據(jù),從而去重。示例代碼如下:
$users?=?Db::name('user') ?????????->field('name,?age') ?????????->group('name') ?????????->select();
上面的代碼中,我們指定 name
字段為分組依據(jù),對 age
distinct
???? ?????. ???? ?? ?????. ??? ?? ?? ?? distinct
???? ???? ???. rrreee
? ????distinct(true)
??? ?? ?? ???? ?? ?? ?????. select()
???? ???? ?? ??? ?? ?? ???? ?????. ????distinct
??? ??? thinkphp? ?? ???? ??? ???? ? ?? ???, ? group
???? ?????. group
??? ???? ???? ??? ??? ???? ??? ??? ? ????. ?? ??? ??? ????. ??rrreee??? ????? name
??? ??? ???? ???? age
??? ?? ?????. ? ??? ???? ?? ?? ??? ??? ? ??? ? ?? ??? ???? ?? ??? ?? ??? ? ??????. ????????? ?? ???? ?? ??? ???? ?? ???? ???? thinkphp? ?? ???? ?? ??? ??? ?????. ?????, ??? ?? ????? ?? ?? ??? ??? ? ????. ? ?? ?? ??? ??? ?? ??? ???? ??? ?? ??? ??? ? ????. ??? ??? thinkphp?? ?? ??? ???? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)