acro Posted March 28, 2013 Share Posted March 28, 2013 Hello everyone! Nice forum, runs real smooth 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 Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/ Share on other sites More sharing options...
Joshua F Posted March 28, 2013 Share Posted March 28, 2013 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. Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/#findComment-1421557 Share on other sites More sharing options...
acro Posted March 28, 2013 Author Share Posted March 28, 2013 Thanks for such a quick response!! Here is the error message I received after running your code. FUNCTION kostcudatabase.RAND does not exist Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/#findComment-1421683 Share on other sites More sharing options...
acro Posted March 28, 2013 Author Share Posted March 28, 2013 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!! Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/#findComment-1421687 Share on other sites More sharing options...
Maq Posted March 28, 2013 Share Posted March 28, 2013 I was going to point that out but on my system (mysql 5.5.29) it doesn't complain about the space after the RAND, only for COUNT. Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/#findComment-1421691 Share on other sites More sharing options...
Joshua F Posted March 28, 2013 Share Posted March 28, 2013 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. Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/#findComment-1421694 Share on other sites More sharing options...
acro Posted March 29, 2013 Author Share Posted March 29, 2013 Thanks everyone, I'm gonna mark this as solved. Link to comment https://forums.phpfreaks.com/topic/276249-warning-mysqli_fetch_array-expects-parameter-1-to-be-mysqli_result-null-given-in-home/#findComment-1421724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.