CodeIgniter는 단순히 MySQL의에서 다단계 범주 계층 구조를 만들방법 멀티 레벨 카테고리 계층 구조 (카테고리 트리) 만들기 -
분류 표 :
________________________________________________________________________
| id | parent_id | name
————————————————————————————————————————————————————————————————————————
| 1 | 0 | Root
| 2 | 1 | Sub category of root
| 3 | 0 | category 1
| 4 | 3 | sub category of category 1
| 5 | 4 | sub category of first sub category of category 1
————————————————————————————————————————————————————————————————————————
PHP
public function getCategoryTree($level = 0) {
$rows = $this->db
->select(‘id,parent_id,name’)
->where(‘parent_id’, $level)
->get(‘categories’)
->result();
if (count($rows) > 0) {
foreach ($rows as $row) {
$rows = $this->getCategoryTree($row->id);
}
}
//return $rows;
}
echo $rows;
// output will be show as string so i have to return this string in a variable
Root
—Sub category of root
category 1
—sub category of category 1
——sub category of first sub category of category 1
가 어떻게 값을 반환 할 수
세부 사항을 이 함수의 문자열 – AZinkey
카테고리 트리가 커지지 않는다면 모든 데이터를 가져 와서 PHP로 정렬 할 수 있습니다. – AmazingDreams