Jump to content

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


acro

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 ;)

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!!

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. :)

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.