Nishan Singha Nishan Singha - 1 month ago 13
MySQL Question

Unknown column in where clause in codeigniter query (Solved)

I have a codeigniter project. I have some dropdowns where i can select campus, session, class, group. I want filter data according to these dropdown values. Here is the function i call-

function student_feeConfig()
{
if ($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');

$campus_id = -1;
$session_id = -1;
$class_id = -1;
$group_id = -1;
if($this->input->post('campus_id') !=null)
$campus_id = $this->input->post('campus_id');
if($this->input->post('session_id') !=null)
$session_id = $this->input->post('session_id');
if($this->input->post('class_id') !=null)
$class_id = $this->input->post('class_id');

if($this->input->post('group_id') !=null)
$group_id = $this->input->post('group_id');
if($this->input->post('section_id') !=null)
$section_id = $this->input->post('section_id');

$campus = $this->db->get('campus')->result_array();
$page_data['campus'] = array(''=>'Select one');
foreach($campus as $row):
$page_data['campus'][$row['id']] = $row['campus_name'];
endforeach;
$page_data['id'] = $campus_id;

$session = $this->db->get('session')->result_array();
$page_data['sessions'] = array(''=>'Select one');
foreach($session as $row):
$page_data['sessions'][$row['id']] = $row['uniqueCode'];
endforeach;
$page_data['session_id'] = $session_id;

$classinfo = $this->db->get_where('class', array('campus_id' => $campus_id))->result_array();
$page_data['classes'] = array(''=>'Select one');
foreach($classinfo as $row):
$page_data['classes'][$row['class_id']] = $row['name'];
endforeach;
$page_data['allclass']=$page_data['classes'];
$page_data['class_id'] = $class_id;

$groups = $this->db->get_where('class_group', array('class_id' => $class_id))->result_array();
$page_data['groups'] = array(''=>'Select one');

foreach($groups as $row):
$page_data['groups'][$row['id']] = $row['group_name'];
endforeach;
$page_data['group_id'] = $group_id;

if($class_id != -1) {
$this->db->select('enroll.group_id, student_feeConfig.*');
$this->db->from('enroll');
$this->db->join('student_feeConfig', 'enroll.student_id = student_feeConfig.student_id');
$this->db->where('enroll.class_id', $class_id);
$feeInfo = $this->db->get()->result_array();
$page_data['feeInfo'] = $feeInfo;
}


$page_data['page_name'] = 'student_feeconf';
$page_data['page_title'] = get_phrase('fee_management');
$this->load->view('backend/index', $page_data);
}


But i get error:

Error Number: 1054

Unknown column 'enroll.class_id' in 'where clause'

UPDATE `ci_sessions` SET `timestamp` = 1478060781 WHERE `enroll`.`class_id` = '4' AND `id` = 'a351278bf35ab714c6f3de3479627cb5c009c7a6'

Filename: libraries/Session/drivers/Session_database_driver.php

Line Number: 243

Answer

Your code is :

if($class_id != -1) {
    $this->db->select('enroll.group_id, student_feeConfig.*');
    $this->db->from('enroll');
    $this->db->join('student_feeConfig', 'enroll.student_id = student_feeConfig.student_id');
    $this->db->where('enroll.class_id', $class_id);
    $feeInfo = $this->db->ge()->result_array(); 
    $page_data['feeInfo'] = $feeInfo;
}

bellow line you used ->db->ge() like this

$feeInfo = $this->db->ge()->result_array(); 

Correction is bellow :

$feeInfo = $this->db->get()->result_array();

and add your enroll.class_id like bellow after if($class_id != -1) { condition:

$this->db->select('enroll.group_id, enroll.class_id, student_feeConfig.*');
Comments