Hello. You need to implement the correct MySQL query. In general, I wondered how to implement the function of subscribing to the latest comments.

There are two tables read: who is subscribed to whom. comments - comments. The read table has 2 columns in which ( kto , kogo ) (Who subscribed (profile ID), To whom subscribed (profile ID)).

The table with comments has columns ( id , id_send_user , id_post , msg , time ) (Post ID, Sender Profile ID, Post ID (entries), Self Comment, Time (php - "time ();")).

In MySQL, I only know how to perform basic actions, so I don’t know how to implement it. Ready to listen to any suggestions. Thank you in advance.

I tried this:

 SELECT * FROM comments JOIN read ON read.kogo = comments.id_send_user ORDER by time desc LIMIT 15 

    1 answer 1

     User { id: int, name: name } Post { id: int, user: int ForeignKey_User_id, date: timestamp, text: text } Comment { id: int, post: int ForeignKey_Post_id, user: int ForeignKey_User_id, date: timestamp, text: text } Subscription { user_src: int ForeignKey_User_id, user_dst: int ForeignKey_User_id } //15 последних комментариев людей на которых я подписался $query = mysql_query( 'SELECT c.* FROM Comment c, Subscription s '. 'WHERE c.user = s.user_src AND s.user_dst = '.$MyID.' ORDER BY time DESC LIMIT 15' ); 
    • Thank you very much! Understood! It was enough for me to just make the right request, but you wrote something over it. - Elected
    • Additionally - the structure of the tables on the pseudo-code ... At a minimum - look at the names of the fields) - timka_s