It would really help to have an outside view to what I am trying to do.
I have 1 users table. 1 posts table and 1 favorites table. Basically what I am trying to do is give a user an option to add other users' posts to their favorites folder.
Say these are the options for each table in mysql.
users::
- id
- username
posts::
- post_id
- user_id
- title
- post
favorites::
- favorite_id
- user_id
- post_id
Now I know I can use joins to join these tables together. I have tried them for other things and they work. It's just that with this particular case, I am having some issues getting the query right.
This is my query. Please point out what's wrong with it and how to do it correctly.
$stmt = $dbh->prepare("SELECT users.*, posts.*, favorites.* FROM posts
LEFT JOIN users ON records.user_id = users.id
LEFT JOIN favorites ON posts.user_id = favorites.id
WHERE posts.user_id = {$userid} ORDER BY posted DESC LIMIT 4");
ps. $userid is definied outside of this query, so don't worry about it.