tags:

views:

37

answers:

2

Can anyone tell me I get the error: Fatal error: Call to a member function fetch_assoc() on a non-object for this method inside the class

This is a recursive function, and it runs fine the first time, is the second time when I get the error.

    function getSite($var, $var1 = 0, $numLevel = 1){
  //get the page
  $qry = "SELECT * FROM table WHERE columnA = $var AND columnB = $var1 ORDER BY parent, position ASC";

  $arrPage = $this->my_sqli->query($qry);

  //a valid resut was returned from the DB
  while($obj =  $arrPage->fetch_assoc()){
   //add to array
   if($obj['id']){
    $this->arrMenu = array(
     'id' => $obj['id'],
     'parent' => $obj['parent'],
     'level' => $numLevel
    );

             ... some more code 

              // call the function again
              getSite($value1);
             }
        }
   }
A: 

Normally when i see those errors there's something wrong with the query, try echo the query and executing it in something like Query Browser

armonge
A: 

You are not including error checking.

Change

$arrPage = $this->my_sqli->query($qry);

to

if ( ($arrPage = $this->my_sqli->query($qry)) === false) {
        printf("Error: %s in query %s\n", $this->my_sqli->error,$qry);
    }
codaddict
This lead me to the right direction. Thanks.
Ole Media