我想做出选择取决于下拉菜单,这是我的代码
视图: -
<select name="class" id="class"> <option selected value='-1'>--Select class--</option> <?php foreach($classes as $class) { echo '<option value="'.$class['class_id'].'">'.$class['class_name'].'</option>'; } ?> </select>
控制器: -
public function select_student($class_id){ <br />$class_id=$this->uri->segment(3);<br /> $this->load->model('select_model');<br /> header('Content-Type: application/x-json; charset=utf-8');<br /> echo(json_encode($this->select_model->student_subject($class_id)));<br />
}
这是我的模型
function student_subject($class_id){<br /> $this->db->select('*');<br /> $this->db->from('student s');<br /> $this->db->join('student_class c','s.student_id=c.student_id', 'left') ;<br /> $this->db-where('s.status',0);<br /> $this->db->where('c.date_of_end !=','0000-00-00');<br /> $this->db->where('c.date_of_end !=', $class_id);<br /> $query = $this->db->get();<br /> if($query->result_array()){<br />
echo '<table cellspacing="10" cellpadding=""><th>Names</th>';
$data='';
$n=0;
foreach($query->result_array() as $name) { $n++;
echo '<tr><td>' .$n .'</td><td>'. $name['firstname'].'</td><td> '.$name['middlename'].'</td><td>'.$name['lastname'].'</td><td><input type="checkbox" name="selected_stds[]" value="'.$name['student_id'].'"></td></tr>';
}
echo '</table>';
return $query->result_array(); }
答案 0 :(得分:0)
在视图页面
<select name="class" id="class">
<option>Select class</option>
<?php foreach($classes as $class){?>
<option value="<?php echo $class['class_id'] ?>">
<?php echo $class['class_name'] ?>
</option>
<?php } ?>
</select>