sixli sixli - 1 year ago 288
PHP Question

prepared statements fetch_assoc php mysqli

I'm having problems with listing out comments with prepared statements. Any ideas?

Here is my code:

$fetchComments = $cnx -> prepare("SELECT comment FROM comments WHERE video_id=? LIMIT 1");
$fetchComments -> bind_param('s', $row['id']);
$fetchComments -> execute();
$fetchComments -> store_result();
$fetchComments -> bind_result($vid_comment);
if ($fetchComments -> num_rows > 0) {
whike ($row = mysqli_fetch_assoc($vid_comment)){
echo $row['comment'];

Answer Source

You have an error in your script. You are using mysqli in object oriented style and you are mixing with procedural style, the error is here

while ($row = mysqli_fetch_assoc($vid_comment)){

So you should use instead

while ($fetchComments ->fetch()) {
   echo $vid_comment 

You can check documentation here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download