开发者

Unique records query

The following query is showing same user for multiple times, how to make it 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开发者_如何学C_id = "3"
          ORDER BY DAYOFMONTH( bday ) ASC';


Add DISTINCT after your SELECT to return only unique rows. So change the first line of your code to the following:

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


Not entirely sure what you're asking but I assume you want a unique identifacation method for your users?

Well in PHP you can hash their ip address and use that as their id, however it contains numbers and letters, so that'll make it unique i suppose :)

Here's how it'll look

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

it'll appear different to everyone, for example, mine appears as the following e36e263f082188a317f89e0dfef766ed

hopefully this is what you're looking for :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜