Codeigniter查询中where子句中的未知列

Codeigniter查询中where子句中的未知列

我有一个代码点火器项目。我有一些下拉列表,可以选择校园,会议,班级,小组。我要根据这些下拉值筛选数据。这是我调用的函数-

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);
    }

但我错了:
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

最佳答案

你的代码是:

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;
}

你这样用的波纹线
$feeInfo = $this->db->ge()->result_array();

更正如下:
$feeInfo = $this->db->get()->result_array();

并在->db->ge()条件后添加您的enroll.class_id如下:
$this->db->select('enroll.group_id, enroll.class_id, student_feeConfig.*');

关于php - Codeigniter查询中where子句中的未知列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40372596/

10-10 04:00