Jump to content

New to PHP 7: mysqli_fetch_assoc not working


dachshund

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.