0

I am getting the fetch_assoc() on a non-object error and I did echo the query and I ran it in PHPMyAdmin. It returns 1 result like it should. But I still get the error when I try to use fetch_assoc().

$autoquery = "SELECT 
               Year,Vozila, Marke_vozila, Model_vozila, bodywork, doors, fuel, gear_box, Tip_vozila, izvedba_vozila, hide 
             FROM vozila_tbl
             WHERE 
               Year = 2008 AND Marke_vozila = 'Iveco' AND Model_vozila = 'Daily' AND Tip_vozila = '29 L 10V 300 H2 | 5-vrata MPV 70 kw (06/06 - 10/11' AND Vozila='Auto' 
             GROUP BY izvedba_vozila 
             ORDER BY izvedba_vozila DESC";

$autoresult = $mysqli->query($autoquery);
$array[0][] = "Birajte ".$option;

//Database values
while($row = $autoresult->fetch_assoc()){ //This is the line it says fetch_assoc() is a non-object
    $array[1][] = $row[$value];
}

$array[1] = print_r($mysqli->error);

return $array;
Sinan Samet
  • 6,432
  • 12
  • 50
  • 93
  • Sorry I just forgot to put that there – Sinan Samet Oct 26 '14 at 16:29
  • which part of the error message is not clear to you? – hakre Oct 26 '14 at 16:31
  • $autoquery lacks a semicolon – Ali Oct 26 '14 at 16:32
  • @Ali: You perhaps mean that the code lacks error handling? (I'm not so sure the ; at the end wouldn't cause this if it's there. It's normally not needed for query.) – hakre Oct 26 '14 at 16:32
  • @hakre That the query is correct but I am still getting the error Ali Yea sorry that was another mistake I just made while making this post. – Sinan Samet Oct 26 '14 at 16:33
  • @SinanSamet: `$mysqli->query` does not always return an object. You have to deal with the return value first and you need to verfiy your expectations. PHP is not lying to you and there ain't an object. But you treat it as one. – hakre Oct 26 '14 at 16:34
  • Alright I used print_r() on $autoresult and it gives me this: mysqli_result Object( [current_field] => 0 [field_count] => 11 [lengths] => [num_rows] => 1 [type] => 0) – Sinan Samet Oct 26 '14 at 16:36

0 Answers0