I have categories and subcategories, but each subcategory has another subcategory, the following code counts the number of pages from the root category, and its subcategories, how do I count the number of pages from the subcategories of the subcategory?
//ΠΠΈΠ΄ΠΆΠ΅Ρ ΡΡΠ°ΡΠΈΡΡΠΈΠΊΠΈ public function show_stats($widget = array()) { //ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ Π²ΡΠ΅ ΠΏΠΎΠ΄ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ $categ = $this->db->query("SELECT id,parent_id FROM category WHERE parent_id=".$widget['settings']['category'])->result_array(); //Π‘ΡΠΈΡΠ°Π΅ΠΌ ΡΡΡΠ°Π½ΠΈΡΡ ΠΊΠ°ΠΆΠ΄ΠΎΠΉ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ $this->db->select('id,category'); $this->db->where('category',$widget['settings']['category']); foreach($categ as $row) { $this->db->or_where('category',$row['id']); } $query = $this->db->get('content'); return $this->template->display('widgets/'.$widget['name'], array('widget' => $widget,'stats' => $query->result_array())); }
Category structure
id parent_id name
Content structure
id, category, title, text
$ widget ['settings'] ['category'] = 0
How to calculate unlimited nesting?