Couple things I see right off the bat - first, you're not escaping any output from the database to the screen. Check out htmlspecialchars() for more information. Secondly, that's a whole lot of HTML inside that PHP. Separate the logic gathering at the top of the file, and if you're feeling up to it, check out a templating system like Twig or Smarty. Twig also handles escaping output, so that'd save you a step. Third, you're preparing the secondary query in a loop. You don't need to. Prepare a query once, run it multiple times with different criteria plugged in. In all honesty, you'd be best to look at rewriting the query so that you don't have to run the secondary query inside a loop, but sometimes it is unavoidable.
Now, as for the actual problem. I'm not sure if this takes care of it or not, but the secondary query isn't actually based on a parent ID. Instead of using s.stat_id = sr.stat_id, try something like this:
$userStatus = $db->prepare("
SELECT status.stat_id
,status.stat_message
,status.username_id
,COUNT(user_interaction.likeStat) AS likes
,user_interaction.shareStat
,status.user_id
,status.postTime
,username.img_path
,status.img_path AS statImg
FROM status
LEFT JOIN username
ON status.user_id = username.user_id
LEFT JOIN stat_replies
ON stat_replies.stat_id = status.stat_id
LEFT JOIN user_interaction
ON user_interaction.stat_id = status.stat_id
WHERE status.user_id = :sessionUsername
OR EXISTS(
SELECT followers.following
FROM followers
WHERE followers.following = 1 AND followers.user_id = :sessionUsername
)
GROUP BY status.stat_id
ORDER BY status.stat_id DESC
");
if ($userStatus->execute(array('sessionUsername'=>$sessionUsername)) == false) {
die("<pre>Query failed:\n" . print_r($status->errorInfo() , 1) . "</pre>");
}
$userStats = $userStatus->fetchAll();
$userReply = $db->prepare("
SELECT sr.stat_answer
,sr.replies_id
,sr.stat_id
,u.img_path
,u.username_id
,u.user_id
,s.stat_id
FROM stat_replies AS sr
LEFT JOIN status AS s
ON s.stat_id = sr.stat_id
LEFT JOIN username u
ON s.user_id = u.user_id
WHERE sr.stat_id = :status_id
");
foreach($userStats as $stat){
$userReply->execute(array('status_id'=>$stat->stat_id));
$usersInput[$stat->stat_id] = $userReply->fetchAll();
}
if(isset($usersInput)){
print("<pre>".print_r($usersInput, true)."</pre>");
}
and see if you're getting the data you expect. Note that this is completely untested code, and I may have transcribed something incorrectly.