Jump to content

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home


Go to solution Solved by Joshua F,

Recommended Posts

Hello everyone! Nice forum, runs real smooth :happy-04:

 

I'm receiving the following error message:

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given (this is on line 6)

Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, null given (this is on line 14)

 

The error is related to the following code:

 

$sql = "SELECT username, avatar FROM users WHERE avatar IS NOT NULL AND activated='1' ORDER BY RAND () LIMIT 32";
$query = mysqli_query($db_conx, $sql);
$userlist = "";
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {   (this is line 6)
    $u = $row["username"];
    $avatar = $row["avatar"];
    $profile_pic = 'user/'.$u.'/'.$avatar;
    $userlist .= '<a href="user.php?u='.$u.'" title="'.$u.'"><img src="'.$profile_pic.'" alt="'.$u.'" style="width: 100px; height: 100px; margin: 10px;"></a>';
}
$sql = "SELECT COUNT (id) FROM users WHERE activated='1'";
$query = mysqli_query($db_conx, $sql);
$row = mysqli_fetch_row ($query); (this is line 14)
$usercount = $row [0];

 

I'm not sure what's causing it, I know it seems to be a problem with a parameter that's not working right, I looked over the code, couldnt find it. I'm wondering if it could be a database issue? but I don't think so. This is a script to show user avatar images in a area of the page. It tells the system to show random user profile pictures if they are registered, activated and have an avatar image.

 

ANY help would be highly appreciated, been trying to solve this for a while now, the rest of the website and script works perfectly so far and there's ALOT of it ;)

Usually this is due to a SQL error, replace $query = mysqli_query($db_conx, $sql); with $query = mysqli_query($db_conx, $sql) or die(mysqli_error($db_conx)); and see if it shows an error.

Edited by Joshua F

Josh, I fixed it!!!! Here was the problem:

 

ORDER BY RAND () (had a space after RAND)

SELECT COUNT (id) (had a space after COUNT)

 

I changed to this:

 

ORDER BY RAND() (no space after RAND)

SELECT COUNT(id) (no space after COUNT)

 

The code now works perfectly!!

 

Thanks for helping me pinpoint the problem!!

  • Solution

Josh, I fixed it!!!! Here was the problem:

 

ORDER BY RAND () (had a space after RAND)

SELECT COUNT (id) (had a space after COUNT)

 

I changed to this:

 

ORDER BY RAND() (no space after RAND)

SELECT COUNT(id) (no space after COUNT)

 

The code now works perfectly!!

 

Thanks for helping me pinpoint the problem!!

 

Well done. :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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