colin96 Posted October 31, 2013 Share Posted October 31, 2013 I've done a search on the error that I've received and following is one possible solution but I can see no reason why it would fail. I've tested my SQL prior to coding and the code works perfectly using xampp so it's related to the server. "The error means what it says, what ever variable you are using in the $result->fetch_assoc() statement isn't an object because your query failed and returned a false value instead of a result object or you overwrote the variable somewhere else in your code." I've tried it on two servers and whilst the following code works on xampp but fails on both servers. Another piece of code from which this was cut/pasted from works on xampp, works on one server but fails on the 2nd. I don't have any access to the configuration of the servers but have to reasonably assume it's in my code. Could it possibly be because I'm using the $mysqli variable more than once? I would have thought it would simply overwrite it. I've also put the top 3 lines of code at the top and run the different sql after branching with the same result. Any thoughts on where to look next?! Thanks, Colin //--------------------------------------------------------------------------------------------------------------------------------------------------- $mysqli = new mysqli("localhost", "login", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;} //--------------------------------------------------------------------------------------------------------------------------------------------------- if( $formField2 == 'd' ){ $sql = "SELECT crewFirstname, crewSurname, count(*) as trips FROM crewmembers GROUP BY crewFirstname, crewSurname ORDER BY trips desc, crewSurname asc"; } else { $sql = "SELECT crewFirstname, crewSurname, count(*) as trips FROM crewmembers GROUP BY crewFirstname, crewSurname ORDER BY crewSurname, crewFirstname asc";} if ( $formField1 > 0 ){ $sql .= " LIMIT " . $formField1;} $mysqli->real_query( $sql );$res = $mysqli->use_result();$crew = array();while ($row = $res->fetch_assoc()) { array_push( $crew, $row );} Quote Link to comment https://forums.phpfreaks.com/topic/283457-fatal-error-call-to-a-member-function-fetch_assoc-on-a-non-object-in/ Share on other sites More sharing options...
requinix Posted October 31, 2013 Share Posted October 31, 2013 Seems you missed half of that quote: The error means what it says, what ever variable you are using in the $result->fetch_assoc() statement isn't an object because your query failed and returned a false value instead of a result object or you overwrote the variable somewhere else in your code.Regardless of how well the code works on other servers, it doesn't work on one of them. So you should be trying to get error messages to find out why. Quote Link to comment https://forums.phpfreaks.com/topic/283457-fatal-error-call-to-a-member-function-fetch_assoc-on-a-non-object-in/#findComment-1456295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.