douluhaikao93943 2014-10-15 06:04
浏览 45
已采纳

社交网站的通知系统

Okay so I am using PHP MySQL .
I Want to Implement a Notification System For A Social Networking Site
Currently I have 2 Tables one For Posts containing columns

    1. id //id of the post
    1. body//
    1. status // For Notifications
    1. user_id// id of the user

Whenever a preson comments or likes a particular post, 1 New record is inserted in the Notification table.
Notification Table Has the following columns

  1. id// id of the notification
  2. src_id // id of the post on which the user commented
  3. type// like , comment etc
  4. user_id //id of the user

So what the problem is that I want to fetch data from notifications table for which the user needs to be notified.


For Example Mysql Query is

SELECT * FROM notifications WHERE src_id IN ("244","245","249") order by src_id

For example I have some data like this in the notifications table

  id  type     user_id  src_id
  1   like      6       244
  2   comment   4       244
  3   like      1       249
  4   comment   8       249
  5   comment   9       245
  6   comment   3       244
  7   like      12      244

How Do i display it in php by grouping them by their src_id

So that I can generate something like this

4,3 commented on your post 244
12,6 liked your post 244
1 liked your post 249
8 commented on your post 249

where 4,3,12,6,1,8 are user_ids

  • 写回答

2条回答 默认 最新

  • dongreng9864 2014-10-15 06:34
    关注

    see in mysql GROUP_CONCAT examples

    edited:

    SELECT 
        group_concat(`user_id`) as 'users'
        , `type`
        , `src_id` as 'post'
    FROM `notifications`
    WHERE `src_id` IN ("244","245","249")
    group by `src_id`, `type`
    ORDER BY `src_id`
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?