Php 如何在where条件下比较多个ID
我在我的Php 如何在where条件下比较多个ID,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,我在我的$temp中有多个ID,比如(7,8,9),我想在我的where条件中比较这些ID,比如$this->db->where\u in('c.mr\u no',$temp)但它只比较第一个id 我试着这样做: 控制器: public function printCollectionRecPage() { $this->load->view('template/header'); $this->load->view('template/sidebar')
$temp
中有多个ID,比如(7,8,9),我想在我的where条件中比较这些ID,比如$this->db->where\u in('c.mr\u no',$temp)代码>但它只比较第一个id
我试着这样做:
控制器:
public function printCollectionRecPage()
{
$this->load->view('template/header');
$this->load->view('template/sidebar');
$temp =($_GET['id']);
$data = array();
$data['collnR'] = $this->PayRecAllModel->printCollectionRecPage($temp);
$this->load->view('crossing/payment_rec_allocation/printCollectionRecovery',$data);
$this->load->view('template/footer');
}
public function printCollectionRecPage($temp)
{
$this->db->select('c.*,payment_rec_allocn.*');
$this->db->from('crossing_cash_memo c');
$this->db->join('payment_rec_allocn', 'payment_rec_allocn.mr_no = c.mr_no');
$this->db->where('c.total !=','0');
$this->db->where('c.mr_no',$temp);
$query = $this->db->get();
return $query->result();
}
型号:
public function printCollectionRecPage()
{
$this->load->view('template/header');
$this->load->view('template/sidebar');
$temp =($_GET['id']);
$data = array();
$data['collnR'] = $this->PayRecAllModel->printCollectionRecPage($temp);
$this->load->view('crossing/payment_rec_allocation/printCollectionRecovery',$data);
$this->load->view('template/footer');
}
public function printCollectionRecPage($temp)
{
$this->db->select('c.*,payment_rec_allocn.*');
$this->db->from('crossing_cash_memo c');
$this->db->join('payment_rec_allocn', 'payment_rec_allocn.mr_no = c.mr_no');
$this->db->where('c.total !=','0');
$this->db->where('c.mr_no',$temp);
$query = $this->db->get();
return $query->result();
}
我想在where条件下比较所有3个ID 我认为您收到了来自$\u GET的字符串,因此比较没有按预期进行
改变这个
$this->db->where('c.mr_no',$temp);
到
然后试试看Where_in将参数排除在数组之外。$this->db->Where_in('c.mr_no',$temp)代码>。Mkae sure$temp=数组(7,8,9)
@AnantSingh---AlivetoDie我用where_in$this->db->where_in('c.mr_no',$temp)代码>但它仍然只比较第一个id(7)@farhantechno,然后它是什么?它是像$temp=“7,8,9”
这样的字符串吗?@farhantechno您是如何存储它们的?把代码给我们看。