CODE点火器数据表查询错误:列' Colname'在where子句中含糊不清

时间:2016-04-29 12:07:44

标签: php mysql codeigniter

您好我正在使用这个带有实时搜索的开源数据表。我已经让其他人运行没有错误,但我已经在这一个上进行了多次连接。我的模特是

var $table = 'emp_201';
    var $column = array('ID','ID_NUM','SURNAME','FNAME','MNAME','STATUS','JOB_NAME','LEAVE_ENTITLED','ES_ID','DEP_ID','SALARY','UPDATED');
    var $order = array('UPDATED' => 'desc');
function __construct() {
    parent::__construct();
}

private function _get_datatables_query()
{

    $this->db->select(' emp_201.ID,
                        employees.ID_NUM,
                        emp_201.STATUS,
                        emp_201.LEAVE_ENTITLED,
                        emp_201.SALARY,
                        emp_201.UPDATED,
                        employees.SURNAME,
                        employees.FNAME,
                        employees.MNAME,
                        job_titles.JOB_NAME,
                        employment_status.ES_NAME,
                        department.DEPARTMENT');
    $this->db->from($this->table);
    $this->db->join('employees','emp_201.ID_NUM = employees.ID_NUM','left');
    $this->db->join('job_titles','emp_201.JOB_ID = job_titles.JOB_ID','left');
    $this->db->join('employment_status','emp_201.ES_ID = employment_status.ES_ID','left');
    $this->db->join('department','emp_201.DEP_ID = department.DEP_ID','left');

    $i = 0;

    foreach ($this->column as $item) 
    {
        if($_POST['search']['value'])
            ($i===0) ? $this->db->like($item, $_POST['search']['value']) : $this->db->or_like($item, $_POST['search']['value']);
        $column[$i] = $item;
        $i++;
    }

    if(isset($_POST['order']))
    {
        $this->db->order_by($column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
    } 
    else if(isset($this->order))
    {
        $order = $this->order;
        $this->db->order_by(key($order), $order[key($order)]);
    }
}

function get_datatables()
{
    $this->_get_datatables_query();
    if($_POST['length'] != -1)
    $this->db->limit($_POST['length'], $_POST['start']);
    $query = $this->db->get();
    return $query->result();
}

function count_filtered()
{
    $this->_get_datatables_query();
    $query = $this->db->get();
    return $query->num_rows();
}

public function count_all()
{
    $this->db->from($this->table);
    return $this->db->count_all_results();
}

然后在我的错误日志上,当我尝试使用实时搜索时,错误是

ERROR - 2016-04-29 14:02:10 --> Query error: Column 'ID_NUM' in where clause is ambiguous - Invalid query: SELECT `emp_201`.`ID`, `employees`.`ID_NUM`, `emp_201`.`STATUS`, `emp_201`.`LEAVE_ENTITLED`, `emp_201`.`SALARY`, `emp_201`.`UPDATED`, `employees`.`SURNAME`, `employees`.`FNAME`, `employees`.`MNAME`, `job_titles`.`JOB_NAME`, `employment_status`.`ES_NAME`, `department`.`DEPARTMENT`
FROM `emp_201`
LEFT JOIN `employees` ON `emp_201`.`ID_NUM` = `employees`.`ID_NUM`
LEFT JOIN `job_titles` ON `emp_201`.`JOB_ID` = `job_titles`.`JOB_ID`
LEFT JOIN `employment_status` ON `emp_201`.`ES_ID` = `employment_status`.`ES_ID`
LEFT JOIN `department` ON `emp_201`.`DEP_ID` = `department`.`DEP_ID`
WHERE `ID` LIKE '%a%' ESCAPE '!'
OR  `ID_NUM` LIKE '%a%' ESCAPE '!'
OR  `SURNAME` LIKE '%a%' ESCAPE '!'
OR  `FNAME` LIKE '%a%' ESCAPE '!'
OR  `MNAME` LIKE '%a%' ESCAPE '!'
OR  `STATUS` LIKE '%a%' ESCAPE '!'
OR  `JOB_NAME` LIKE '%a%' ESCAPE '!'
OR  `LEAVE_ENTITLED` LIKE '%a%' ESCAPE '!'
OR  `ES_ID` LIKE '%a%' ESCAPE '!'
OR  `DEP_ID` LIKE '%a%' ESCAPE '!'
OR  `SALARY` LIKE '%a%' ESCAPE '!'
OR  `UPDATED` LIKE '%a%' ESCAPE '!'
ORDER BY `ID` ASC
 LIMIT 10

所有连接的表都有相同的错误..

我仍然不擅长从codeigniter查询制作者进行查询。什么是错误,我该怎么做才能纠正它?

1 个答案:

答案 0 :(得分:-1)

在您的where子句中,您需要指定所需的ID_NUM ..是employees.ID_NUM还是emp_201.ID_NUM