如果我在单独的地方使用,搜索就可以了,但是在代码点火器的ajax数据表中不能使用多个。我已经使用了不同类型的地方,你可以在评论的代码中看到,除了单一的地方没有任何作用。
public function get_data1($status, $status1, $id = 0)
{
$column_order = array('s.student_name', 's.student_national_id', 'r.registration_test', 'r.registration_fee', 'r.registration_status');
$column_search = array('s.student_name', 's.student_national_id', 'r.registration_test', 'r.registration_fee', 'r.registration_status');
$order = array('s.id' => 'desc');
$this->db->select('*,count(e.id) as email_count');
$this->db->from('student s');
$this->db->join('email e', 's.id = e.student_id', 'left');
$this->db->join('registration r', 'r.student_id = s.id', 'left');
$this->db->join('classes cl', 'r.class_id = cl.id', 'left');
$this->db->join('student_contact sc', 'sc.student_id = s.id', 'left');
$this->db->join('contact c', 'c.id = sc.contact_id', 'inner');
$this->db->join('address a', 'a.contact_id = c.id', 'left');
$this->db->join('branch b', 'b.id = r.branch_id', 'left');
if($status != '')
{
// $query="SELECT * FROM `registration` where `registration_status` = 'registered' OR `registration_status` = 'payment pending'";
// $this->db->query($query);
// $where = "r.registration_status='registered' OR r.registration_status='payment pending'";
// $this->db->where($where);
// $where = array('r.registration_status' => $status);
// $where1 = array('r.registration_status' => $status1);
// $this->db->where($where);
// $this->db->or_where($where1);
// $this->db->where('r.registration_status'= $status OR 'r.registration_status'= $status1);
// $where = "r.registration_status='registered' OR r.registration_status='payment pending'";
// $this->db->where($where);
// $this->db->or_where_in('r.registration_status',$status1);
$this->db->where('r.registration_status', $status);
// $this->db->or_where('r.registration_status', $status1);
}
$this->db->group_by('s.id');
//$this->db->order_by('r.registration_date', 'desc');
$i = 0;
if($id==0)
{
foreach ($column_search as $key=>$item) // loop column
{
if($_POST['search']['value']) // if datatable send POST for search
{
$search_value = $_POST['search']['value'];
$search_text = $search_value;
if($i===0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $search_text);
}
else
{
$this->db->or_like($item, $search_text);
}
if(count($column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
else
if($_POST['columns']) // if datatable send POST for column search
{
$search_value = $_POST['columns'][$key]['search']['value'];
$search_text = $search_value;
if($search_text!='')
{
$this->db->where($item, $search_text);
}
}
$i++;
}
if(isset($_POST['order'])) // here order processing
{
$this->db->order_by($column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($order))
{
$order = $order;
$this->db->order_by(key($order), $order[key($order)]);
}
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
return $query->result_array();
}
}
我已经尝试了各种各样的地方,但搜索仅在只有1个我需要从3种类型的数据中获取2种类型的数据时才有效。所以我用了2次。
答案 0 :(得分:0)
您不能在where子句中使用数组。
请试试这个:
离。
$this->db->where('r.registration_status', 'registered');
$this->db->or_where('r.registration_status', 'payment pending');
OR
离。
$types = array('registered', 'payment pending');
$this->db->where_in('r.registration_status', $types);