簡體   English   中英

codeigniter數據庫where_in錯誤

[英]codeigniter database where_in error

我很困惑。 我正在嘗試以下查詢:

$this->db->select('id')->from("orders")->where("status", "Active")->where_in($this->session->id, $this->db->query("SELECT `associated_staffs` FROM `orders` WHERE `status`='Active'")->result());
$total_rows = $this->db->count_all_results();

它在sql查詢下生成:

SELECT COUNT(*) AS `numrows` FROM `orders` WHERE `status` = 'Active' AND 3 IN(, )

但它應該生成:

SELECT COUNT(*) AS `numrows` FROM `orders` WHERE `status` = 'Active' AND 3 IN(3,14,2 )

無論如何我都沒有怎么做。 請幫忙

您可以使用類似

    $this->db->where(array('active' => 1));
    $this->db->from('cars'); //table name here
    $this->db->where_in('id', array(1, 2, 3, 3)); //pass yoru where_in values here
    $cars = $this->db->count_all_results();
    echo $cars;
    echo $this->db->last_query();

輸出:

選擇COUNT(*) numrowsactive cars = 1 AND id IN( numrows

試試這個簡單的方法

$query = $this->db->query("SELECT id FROM orders WHERE status = 'Active' AND 3 IN(3,14,2)");
$result = $query->result_array();
return $result;

嘗試這個

  $this->db->select('COUNT(*) AS numrows');
  $this->db->from('orders');
  $this->db->where_in(3,array(3,14,2));
  $this->db->where('status','Active');
  $query=$this->db->get();

  $result=$query->row();
  echo $result->numrows;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM