【问题标题】:How can I Compare multiple ids in where condition如何在 where 条件下比较多个 id
【发布时间】:2019-07-31 10:58:10
【问题描述】:

我的$temp like(7,8,9) 中有多个 ID,我想比较我的 where 条件中的 ID,例如 $this->db->where_in('c.mr_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();
}    

我想在 where 条件下比较所有 3 个 id。

【问题讨论】:

  • $this->db->where_in('c.mr_no',$temp); 。确定$temp = array(7,8,9);
  • @AnantSingh---AlivetoDie 我使用 where_in $this->db->where_in('c.mr_no',$temp); 但它仍然只比较第一个 id(7)
  • @farhantechno 那么它是什么?是像$temp ="7,8,9" 这样的字符串吗?
  • @farhantechno 你是如何存储它们的?向我们展示该代码。

标签: php mysql sql codeigniter


【解决方案1】:

我认为您收到了来自 $_GET 的字符串,因此比较没有按预期进行。

改变这个

$this->db->where('c.mr_no',$temp);

$temp = explode(",", $temp);
$this->db->where_in('c.mr_no',$temp);

然后尝试。 Where_in 将参数除外为数组。

【讨论】:

    猜你喜欢
    • 2015-07-08
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2017-02-28
    • 2020-12-21
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多