0
나는 CI에서 동적 인 드롭 다운을 만들고 싶다. 나는 모델에서 값을 직접 전달함으로써 CI에서 그것을 수행했다. 연결에 의한 디자인은 html로한다.하지만 이제는 html없이 함수를 반환한다. 배열은 ... 내 전 기능 ... 나는 이런 식으로 뭔가를 드롭 다운 만들고 싶어PHP에서 동적 드롭 다운하는 방법?
function category() {
$sql = $this->db->query("select * from ss_category where parent_id='0'");
$result = $sql->result();
//print_r($result);die();
$output = array();
foreach ($result as $ra) {
$output=$this->get_child($ra->cat_id);
}
//print_r($output);die();
return $output;
}
function get_child($parent_id) {
//echo "select * from ss_category where parent_id=" . $parent_id;
$sql = $this->db->query("select * from ss_category where parent_id=" . $parent_id);
$r = $sql->result();
if (!empty($r)) {
foreach ($r as $s) {
$this->get_child($s->cat_id);
}
//print_r($child);
}
//print_r($r);
}
이 같은했다 ..
-parent 1
-child 1
-subchild 1
-child 2
-child 3
-subchild 1
-parent 2
-child 1
내 테이블 구조는 다음과 같이이다 ..
+---------------------------------------------------------------+
| cat_id category_name cat_slug parent_id level description |
+---------------------------------------------------------------+
| 1 Elecotronics Electronics 1 description |
+---------------------------------------------------------------+
당신은 중첩 된'foreach' :) 3x가 필요할 것입니다. 게시물을 편집하고 테이블 구조를 추가하십시오, 감사합니다. – Kyslik
'subchild '는 어떻게 정의되어 있습니까? 나무 구조 (하위 1, 하위 2)를 나타내는 두 개의 행을 표에 채워주십시오. 감사합니다. – Kyslik
친애하는 Kyslik 저는 부모가 자식 수를 가질 수있는 드롭 다운을 만들고 싶습니다. 자녀에게 하위 자식이있는 경우 하위도 부모가 될 수 있습니다 ... – Drudge