I am working on a page, thats like facebook feed page. So, my query now look like that:
$sql = "SELECT *
FROM event
WHERE id_user IN (
SELECT a.id_user_stalkers
FROM stalkers a
WHERE a.id_user = ".$id_profile.")
ORDER by date DESC
LIMIT 0, 10";
stalkers - friends
Table Stalkers:
id id_user id_user_friend
I need to append to that IN clause my personal ID, so my qyery returns my events and my friends event.
Can anybody help me ?
What I have tried
$sql = "SELECT *
FROM event
WHERE id_user IN (
SELECT a.id_user_stalkers
FROM stalkers a
WHERE a.id_user = ".$id_profile.")
OR id_user = ".$id_profile."
ORDER by date DESC
LIMIT 0, 10";
it looks something wrong in your sql and your table
1-in your table you have id_user_friend
and in your sql you are making id_user_stalkers
.
2- i dont know if you have date in your first table , or you mean NOW()
.? since u didnt share the first table.
try this
$sql = "SELECT * FROM event e WHERE id_user
IN (SELECT a.id_user_friend FROM stalkers a
WHERE a.id_user = ".$id_profile.")
OR e.id_user = ".$id_user."
ORDER by e.date DESC LIMIT 0, 10";
What is $id_user ? The original query only has one variable. I don't see why you need another. In other words, try this:
SELECT *
FROM event e
WHERE id_user IN (SELECT a.id_user_friend
FROM stalkers a
WHERE a.id_user = ".$id_profile."
) OR
e.id_user = ".$id_profile."
ORDER by e.date DESC LIMIT 0, 10