robins robins - 7 months ago 16
PHP Question

The passed data is missing in model

In my model function contain variables from controller.But that value got from controller.But it is not get into model.

model

function get_sub_marks_data($division,$subj_name)
{
$sql = "SELECT student_name,".$subj_name." AS marks FROM f_tbl WHERE
division='".$division."' ORDER BY student_name asc";
echo $sql;
$query=$this->db->query($sql);
return $query;
}


controller

Post data from ajax

function get_subject_wise_marks()
{
$subj_name=$this->input->post('sub');
$exam=$this->input->post('exam');
// $classid=6;
$division='A';

$subj_name = strtolower($subj_name);
if($exam == 't1'||$exam == 't2')
{
$subj_name= $exam.'_10_'.$subj_name;

}
else if($exam == 't3'|| $exam == 't4')
{
$subj_name= $exam.'_20_'.$subj_name;
}
$sub_marks=$this->IM->get_sub_marks_data($division,$subj_name);

}


$subj_name the value is not get into model..

Ajax

function sub_dat(subject)
{
alert(subject);
var exam=$("li.lists.active").attr('id');
alert(exam);
$.ajax({
url:"<? echo base_url();?>homeindex/get_subject_wise_marks",
dataType: 'json',
type: "POST",
data: {sub:subject,exam:exam},
success:function(result) {
alert(result)
console.log(result);
}
});


}

Any mistakes in this..

Answer

Have you considered to load the model before

$sub_marks=$this->IM->get_sub_marks_data($division,$subj_name);  ???

Cause I don't see any loading of the model in your code. So try this :

 ...
 $this->load->model('IM');
 $sub_marks=$this->IM->get_sub_marks_data($division,$subj_name); 

Tell me if that worked for you

Comments