I want to bind the result from prepared query which is in while stmt. But it gives me the error
Call to a member function bind_param
We all know this obvious error message... I just don't know why is this error popping out...
Here is my php code (session is started and all rows and columns are correct)
$selectposts = "SELECT postby,posttxt,time,upvotes,downvotes FROM posts ORDER BY id DESC";
$stmt = $mysqli->prepare($selectposts);
$stmt->execute();
$stmt->bind_result($postby,$posttxt,$posttime,$upvotes,$downvotes);
while($stmt->fetch()){
$picturestmt = $mysqli->prepare("SELECT picture FROM members WHERE username = ?");
$picturestmt->bind_param('s', $postby);
$picturestmt->execute();
$picturestmt->bind_result($picture);
while($picturestmt->fetch()){
if(empty($picture)){
$profpicturefromdb = " <img src='profile_pictures/public_icon.png' width='25' height='25' class='fxdmimg'>";
} else {
$profpicturefromdb = " <img width='25' class='fxdmimg' height='25' src='profile_pictures/".$picture."' alt='Profile Picture'>";
}
}
}
This code should assign the $profpicturefromdb to an image. (And also pull out all posts from database but that's another echo)
If I echo the $postby, it shows the name of user who posted the post. That's fine, but why it does not assign that to the "bind_param('s',$postby');
?
Thanks