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)){ Link to comment 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. Link to comment 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 Link to comment 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'); Link to comment Share on other sites More sharing options...
Barand Posted April 5, 2018 Share Posted April 5, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.