Tracking and posting system (social network type)

4


I am developing a new project and I am creating a system of profile followers, in which the purpose is to show only the publications of whom I follow. Like for example the one of a social network. I follow the person, so I get the person's publications on the homepage.

My difficulty is to show only the publications I follow. Home Example:


WhatIthinkisthatIhavetojoinmy2tablesinonly1query,butIthinkIcannotuse"UNION" in any way ...
You're probably in the wrong rationale, forgive me ... Here are my necessary mysql tables.


I already tried several querys but I could not reach a resolution. Is it better to make 2 querys and compare with a while or if? If so ... how? Greetings to all and thank you one more time. Home PS: I'm doing it in pdo.

    
asked by anonymous 13.12.2014 / 19:59

1 answer

1

The problem of PDO is that it needs to fit any database, but it does not always work.

For example, the solution in MySQL is different from the solution in SQL Server, which tends to be different in PostgreSQL.

Generally you would do something like

SELECT post.* FROM post, follow WHERE follow.userid=post.userid and follow.whofollowid=CODIGO_USER_LOGADO_ATUAL ORDER BY POST.data_registro desc

But you did not enter the content of the userid and whofollowid fields. I have compared the userid of the two tables, but maybe it is reversed, such as:

SELECT post.* FROM post, follow WHERE follow.whofollowid=post.userid and follow.userid=CODIGO_USER_LOGADO_ATUAL

As you mentioned that worked for you was my second option I had posted in the comment (and I posted above too):

SELECT post.* FROM post, follow WHERE follow.whofollowid = post.userid and follow.userid = ? ORDER BY date DESC, time DESC
    
03.01.2015 / 06:49