Code: Select all
| id | parent | slug | name |
-----------------------------------------
| 1 | 0 | animations | animations |
| 2 | 1 | flash | flash |
| 3 | 2 | looped | looped |
| 4 | 1 | gif | gif images |
Das eigentliche Problem besteht darin, dass ich mit „category/$parent_slug/$child_slug“ nach Ergebnissen suchen muss und stattdessen IDs (category/$id) verwenden muss, um |3|2|looped|looped| zu erhalten.
Das ist was Ich habe bisher:
Code: Select all
function get_category_childrens($category_parent=null){
$this->db->select('*');
if(!is_null($category_parent)){
$this->db->where('categories.slug', $category_parent);
$this->db->join('categories as l1', 'l1.parent = categories.id', 'left');
}
else{
$this->db->where('categories.parent', '0');
}
$query = $this->db->get('categories');
return $query->result_array();
}
Code: Select all
SELECT *
FROM (`categories`)
LEFT JOIN `categories` as l1 ON `l1`.`parent` = `categories`.`id`
WHERE `categories`.`slug` = 'animations'
Mobile version