0
我有保留這下遞歸函數返回500錯誤遞歸函數返回500錯誤
public function get_parent($cat=0){
$ci = &get_instance();
$q= $ci->db->query("SELECT category_id,parent_id FROM tbl_products_categories WHERE category_id = {$cat}");
if($q->num_rows()>0){
$row = $q->row();
if($row->parent_id == 0){
return $row->category_id;
break;
}else if($row->parent_id != 0){
$this->get_parent($row->category_id) ;
}
}
else{
return 0;
}
}
我打電話像這樣的功能:
$cat = 9;
$main_cat =$this->get_parent($cat);