foreach ($getComments as $comments) {
$comAuthor=$comments['uid'];
$getUser = $pdo->query("SELECT * FROM user WHERE uid = $comAuthor")->fetch();
$user = $getUser['name'];
$comContent=$comments['cdata'];
$comLikes=$comments['likes'];
echo "<div class='comment'><a href='profile?uid=$comAuthor'>$user</a><p>$comContent</p><likes>$comLikes</likes></div>";
}
I have been trying to get this query to work in a forEach cycle, but after I have done my research I found out it's impossible to run it more than once. I need help trying to get this to work. I am new to PHP and a lot of stuff is unfamiliar to me.
My Answer:
>prepare("SELECT * FROM users WHERE id = :id");
$getUser->bindParam(':id', $comAuthor);
$getUser->execute();
$user = $getUser->fetch(PDO::FETCH_ASSOC);
echo "Comment Author: " . $user['username'] . "
";
echo "Comment: " . $comments['comment'] . "
";
}_
Rate this post
3 of 5 based on 8629 votesComments