dachshund Posted April 5, 2018 Share Posted April 5, 2018 Hi, I'm just changing all my old PHP 5 code to PHP 7, which I'm very new to, and have come across some issues. The below code is giving this error: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in Any help much appreciated: $sql = "SELECT * FROM content WHERE `live` LIKE '0' AND `featured` LIKE '1'"; $result = mysqli_query($con, $sql); while($rows=mysqli_fetch_assoc($result)){ Quote Link to comment https://forums.phpfreaks.com/topic/307056-new-to-php-7-mysqli_fetch_assoc-not-working/ Share on other sites More sharing options...
Barand Posted April 5, 2018 Share Posted April 5, 2018 If $result is a boolean value (ie false) your query failed. Quote Link to comment https://forums.phpfreaks.com/topic/307056-new-to-php-7-mysqli_fetch_assoc-not-working/#findComment-1557663 Share on other sites More sharing options...
dachshund Posted April 5, 2018 Author Share Posted April 5, 2018 Thanks, but do you know why it's failing? It works fine in PHP 5 Quote Link to comment https://forums.phpfreaks.com/topic/307056-new-to-php-7-mysqli_fetch_assoc-not-working/#findComment-1557664 Share on other sites More sharing options...
dachshund Posted April 5, 2018 Author Share Posted April 5, 2018 This is $con, by the way (obviously with correct values): $con = new mysqli('localhost', 'username', 'password', 'database_name'); Quote Link to comment https://forums.phpfreaks.com/topic/307056-new-to-php-7-mysqli_fetch_assoc-not-working/#findComment-1557665 Share on other sites More sharing options...
Barand Posted April 5, 2018 Share Posted April 5, 2018 (edited) Thanks, but do you know why it's failing? It works fine in PHP 5 No, but it does. Check the value in mysqli_error Also you use of LIKE is incorrect. LIKE is for matching with wildcard characters (eg WHERE lastname LIKE 'Jon%' to find names beginning with "Jon". You should be using "=" SELECT * FROM content WHERE `live` = 0 AND `featured` = 1; or even SELECT * FROM content WHERE NOT `live` AND `featured`; Secondly, avoid "SELECT STAR" - specify the columns you want returned. Edited April 5, 2018 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/307056-new-to-php-7-mysqli_fetch_assoc-not-working/#findComment-1557666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.