我已經使用活動記錄在codeigniter中編寫了一個搜索函數。我想要做的是,如果payment_type = 5並且在相同的記錄order_status = 1中,那麼我想省略它。但是可以有記錄,其中payment_type = 5和order_status = 2。如果並且只有兩個條件都滿足,則必須省略該記錄。 (payment_type = 5 AND order_status = 1)。我已經添加了下面的模型功能。我想知道如何使用活動記錄來做到這一點。如果任何人有任何想法,這將是真正有用的。提前致謝。如何在Codeigniter活動記錄中使用where_not_in()和兩個條件?
public function getSalesByStore($from,$to,$status,$filter_stores,$offset, $amount, $limit = '')
{
$result = array();
$this->db->select("*,a.created AS order_created,store_name, users.name, a.id as orderid, a.payment_type AS payment");
$this->db->from("$this->table a");
$this->db->join('users', "a.customer_id = users.id");
$this->db->join('stores', "a.store_id = stores.id");
$this->db->order_by("a.id", "desc");
if(!empty($status))
{
if ($status == 6)
{
$this->db->where('order_status != 3');
}
elseif ($status == 1)
{
$this->db->where("a.payment_type != 5 AND order_status = $status");
}
else
{
$this->db->where('order_status', $status);
}
}
if(!empty($filter_stores))
{
$this->db->where('store_id in ('.$filter_stores.')');
}
if(!empty($from))
{
$this->db->where('date(a.created) >=', date($from));
}
if(!empty($to))
{
$this->db->where('date(a.created) <=', date($to));
}
if(!empty($amount))
{
if ($amount == 1)
{
$this->db->where("a.total_amount <=", 50);
}else if ($amount == 2)
{
$this->db->where("a.total_amount >=", 50);
}
}
$this->db->limit($limit, $offset);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$row->order_status = $this->get_status($row->order_status);
$result [] = $row;
}
}
return $result;
}
答案看這裏的https://www.codeigniter。 com/userguide3/database/query_builder.html#this-for-specific-data for'$ this-> db-> where_in()'和'$ this-> db-> where_not_in()'。 – RanjanaLK