Hello,
I have students database from which I want to access students data based on class section, when any section is selected from dropdown list.
For I tried below:
my jquery is below, where sections is my dropdown id.
Code:
$("#sections").change(function(){
var sectionid = $(this).val();
$.ajax({
url: "<?php echo $baseurl; ?>/Students/getStudents",
type: "POST",
data:{sectionid:sectionid},
success:function(data)
{
// $("#session").find('option').not(':first').remove();
// $("#sections").html(data);
}
});
});
getStudents function in controller Students is below:
PHP Code:
public function getStudents()
{
$model =new StudentModel();
if($this->request->getVar('sectionid'))
{
$id = $this->request->getVar('sectionid');
return $model->getStudents($id);
}
}
and the getStudents function with param function in StudentModel is:
PHP Code:
public function getStudents($id)
{
$sectionid = $id;
$sql = "SELECT s.*, e.* FROM tblstudents s INNER JOIN tblenrollment e ON s.id = e.studentid WHERE e.sectionid=?";
$query = $this->db->query($sql,$sectionid);
$results = $query->getResult();
return $results;
}
now my problem is to retrieve these values in my view
I tried like below, but it requires parameter, please help.
PHP Code:
$data['students'] = $model->getStudents();