Link to home
Start Free TrialLog in
Avatar of prashanth ag
prashanth ag

asked on

Fatal error: Call to a member function fetch_assoc() on a non-object/ boolean

HI

Plz find the code
$query = "SELECT * FROM $this->_table_users WHERE manager_code = $manager_code AND date_leave = 0 ORDER BY emp_code DESC LIMIT $this->_offset,$this->_limit";
$query = mysqli_query($this->_dbconnect, $query);
$result = array();
$i = 0;
while($res = $query->fetch_assoc()){  //Error 
$result[$i] = $res;
$i++;
}
return $result;

Open in new window

it shows Fatal error suppose manager_code  =car1002, Xyz007, (alpha numeric value)
  if manager_code = 1001, 2003 (numeric)  works fine and don't get any error
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This error occurs because the query failed.  MySQL is not a black box - it can and will fail for reasons that are not always 100% in your control.  To find out why it failed, add these statements after line 2:

if (!$query)
{
    var_dump(mysqli_error($this->_dbconnect));
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the output of var_dump()?
@julianH: Sorry, but I do not have enough time left in life to guess about what novice programmers are doing.  That's why we ask pointed questions -- we want to lead them to the water, even if we cannot make them drink.  I don't really care about the exact solution so much as teaching the process of finding the solution.  I already know the solutions.  I just want someone who asks a question here to leave with a new tool for finding the next solution!  Sometimes that is a process of learning what question to ask of themselves, like, "What is in my variable?"