While loop PHP get_result not working

后端 未结 1 1492
难免孤独
难免孤独 2021-01-21 18:24

I am trying to get rows from the database using MySQl prepared statements and get result. However this is not working.

Please can someone see where I am going wrong? I

相关标签:
1条回答
  • 2021-01-21 19:08

    Try this:

    $stmt = $mysqli->prepare('SELECT posts.id FROM tags JOIN posts ON posts.id = tags.post_id WHERE tag = ?');
    
    ...
    
    $stmt->bind_result($id);    
    
    while ($stmt->fetch()) {
    
        // var_dump entire row to ensure the key you expect is avail
        var_dump($id);
    
    }
    

    Upate

    If you want to do a select *, vs having to specify EVERY column individually, check out this post (not the accepted answer, but the highest scoring answer). Otherwise I strongly urge you to check out PDO, as it makes these basic read ops much easier.

    0 讨论(0)
提交回复
热议问题