我已经使用活动记录在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