I updated this question as it was pointed out to change the query and the how implode was used. I have added the query again after reading through the suggested SO posts. I am still learning PDO so I apologize if I made a mistake.
Here is the query:
$group_array = implode(',', $groups);
$friend_array = implode(',', $friends);
$stmt = $db->prepare("SELECT *
FROM statuses
WHERE parent_id = 0
AND ( user_id = :auth_id
OR FIND_IN_SET(group_id, :group_array)
OR FIND_IN_SET(user_id, :friend_array)
)
ORDER BY updated_at DESC LIMIT :start,
:per_page");
$stmt->bindParam(':auth_id', $user_id);
$stmt->bindParam(':group_array', $group_array);
$stmt->bindParam(':friend_array', $friend_array);
$stmt->bindParam(':start', $start);
$stmt->bindParam(':per_page', $per_page);
$stmt->execute();
if ($stmt->rowCount() > 0) {
while($row = $stmt->fetchAll()) {
return $row;
}
}
When I var_dump the friends and group I get the following results:
friend array: array(2) { [0]=> string(2) "25" [1]=> string(2) "27" }
group array: array(2) { [0]=> NULL [1]=> NULL }
And when I test it using the following query it only returns statuses with the user id of 26(auth_id) and nothing from the friend array id's 25 or 27.
SELECT * FROM statuses WHERE parent_id = 0 AND (user_id = 26 OR FIND_IN_SET(group_id, '') OR FIND_IN_SET(user_id, 27)) ORDER BY updated_at DESC LIMIT 0, 10
Can anyone tell me shed some light on this?