开发者

PHP/mysql result set not repeating the same user

In php I have a results set that show similar results of another. How do I have the similar result set include one result for per user instead of showing multiple results per user.

For example, I want the similar result set like this unique to each user:

user A 
user C
user F
user B

not like this:

user A
user C
user A
user A
user D
user C

etc... because it here it shows different results for the same use开发者_运维问答r i.e. user a, c.

In php do I need to create a foreach loop so the result set doesn't repeat the same user.


You could use DISTINCT in your SQL query.

A bit like this :

select distinct username
from users
where ...


You can use http://php.net/manual/en/function.array-unique.php in PHP or SELECT DISTINCT in MySQL...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜