0

Getting Error in line 29 where it states $tree[$child['parent_id']]['children'][] = $child; I am uing php5.5 Error Log showing: PHP Warning: Illegal string offset 'parent_id' in /home/mysite.com/public_html/app/controllers/webController.php on line 29

     public function getchild($parentID) {
      $sql = "select id, parent_id from category where ";
      if ( is_null($parentID) ) {
          $sql .= "parent_id = 0";
      }
      else if ( is_array($parentID) ) {
          $parentID = implode(',', $parentID);
          $sql .= "parent_id in ({$parentID})";
      }
      else {
          $sql .= "parent_id = {$parentID}";
      }

      $tree = array();
      $idList = array();
      if($this->db->count($sql)){
          $res = $this->db->fetchAll($sql) ;
          if(count($res)>0){
            foreach($res as $row){
              $tree[$row['id']] = $row;
              $idList[] = $row['id'];
            }

          }

           if (isset($idList) && is_array($idList)) {
              $children = $this->getchild($idList);
              foreach($children as $child) {
                $tree[$child['parent_id']]['children'][] = $child;
              }
          }
          return $tree;
      }
      else
      {
        $tree['id'] = $parentID;
         return $tree;
      }
  }

Please do let me know what am I doing wrong or how to fix the error. Thanks in advance

0 Answers0