0
我需要顯示下拉列表包含的課程,我寫這段代碼來做到這一點。但我的問題是它很好地顯示課程類別和子類別。但我需要將類別包裝到選項組標籤中。我厭倦這樣做,但失敗了。Php recrussive下拉菜單幫助nedded
這是我的表結構
id parent_id course_name
1 0 UG
2 0 PG
3 1 Bsc
4 3 Computer science
5 3 Chemisty
6 2 Msc
7 6 Computer science
8 6 Chemistry
這裏是recurssion
function load_course_category(){
$this->db->select('*');
$this->db->from('courses_category');
$this->db->where('parent_id','0');
$this->db->order_by("id", "desc");
$query = $this->db->get();
foreach($query->result() as $row) {
$this->db->where('parent_id', $row->id);
$this->db->from('courses_category');
$count = $this->db->count_all_results();
if($count>0){
echo '<optiongroup label="'.$row->course_name.'">';
}else{
echo '<optiongroup label="'.$row->course_name.'"></optiongroup>';
}
$this->get_children($row->id);
}
}
function get_children($parent, $level = 1){
$this->db->select('*');
$this->db->from('courses_category');
$this->db->where('parent_id',$parent);
$this->db->order_by("id", "desc");
$query = $this->db->get();
if($query->num_rows()>0){
foreach($query->result() as $row) {
$this->db->where('parent_id', $row->id);
$this->db->from('courses_category');
$count = $this->db->count_all_results();
if($count>0){
echo '<optiongroup label="'.$row->course_name.'">';
}else{
echo '<optiongroup label="'.$row->course_name.'"></optiongroup>';
}
$this->get_children($row->id, $level+1);
}
}
}
這裏的選項組沒有正確關閉PHP代碼。任何人都可以幫我糾正這個問題嗎?
謝謝。