I am using following code to query
$statement = $conn->prepare('SELECT * FROM userFeeds WHERE userId = :userId ORDER BY creationDate ASC LIMIT 100');
$statement->bindParam(':userId' , $userId, PDO::PARAM_STR);
$statement->execute();
$posts = $statement->fetchAll(PDO::FETCH_ASSOC);
return array('Success'=>$row, 'Posts'=>$posts);
Each post has following feilds,
id userId comment type date
I also want to get the UserInfo of each post along with the other fields of posts.
Currently in JSON i am getting above fields, but If i want to add an extra field "user" and pass user to it e.g
foreach ($post in $posts)
{
// PERFORM A QUERY TO GET USER FROM post=>userId
$post['user'] = $user;
}
This loop could be a long thing. Can I manage to do something more efficiently or in one query only?