Jump to content

New to PHP 7: mysqli_fetch_assoc not working


dachshund
 Share

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.

Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.