唯一记录查询

时间:2011-05-22 04:18:06

标签: unique

以下查询多次显示同一用户,如何使其唯一?

$query = 'SELECT   a.connection_id, a.connect_from, a.connect_to,
                   b.userid, b.thumb, c.name, d.user_id, d.field_id,
                   d.value as bday, e.creator, e.id as videoprofile,
                   DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),d.value)), "%Y")+0 AS age
          FROM     `#__community_connection` AS a 
                   LEFT JOIN `#__community_users` AS b
                       ON a.connect_to = b.userid
                   LEFT JOIN `#__users` AS c ON a.connect_to = c.id
                   LEFT JOIN `#__community_fields_values` AS d
                       ON a.connect_to = d.user_id
                   LEFT JOIN `#__community_videos` AS e ON a.connect_to = e.creator
          WHERE    a.connect_from = "' . $uid .'" AND d.field_id = "3"
          ORDER BY DAYOFMONTH( bday ) ASC';

2 个答案:

答案 0 :(得分:2)

DISTINCT之后添加SELECT,仅返回唯一的行。因此,将代码的第一行更改为以下内容:

$query = 'SELECT DISTINCT  a.connection_id, a.connect_from, a.connect_to, ...
[The rest of your query follows here.]

答案 1 :(得分:0)

不完全确定您的要求,但我认为您需要为用户提供独特的识别方法?

在PHP中你可以哈希他们的ip地址并使用它作为他们的id,但它包含数字和字母,所以这将使它独特我想:)

以下是它的外观

.md5($data['post_ip']);

它似乎与每个人不同,例如,我的如下所示 e36e263f082188a317f89e0dfef766ed

希望这就是你要找的东西:)