Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 先按非空字段下单_Php_Activerecord_Codeigniter 2 - Fatal编程技术网

Php 先按非空字段下单

Php 先按非空字段下单,php,activerecord,codeigniter-2,Php,Activerecord,Codeigniter 2,我正在使用Codeigniter 2 ActiveRecord执行一个查询。 在我的表中,我有两个字段降价(可以为空)和价格。我希望订购人首先检查降价,如果为空,则使用降价 我当前的代码如下所示: $this->db->select('*') ->from('products') ->order_by('reduced_price', 'desc') ->get() ->resul

我正在使用Codeigniter 2 ActiveRecord执行一个查询。 在我的表中,我有两个字段
降价
(可以为空)和
价格
。我希望订购人首先检查降价,如果为空,则使用降价

我当前的代码如下所示:

$this->db->select('*')
          ->from('products')
          ->order_by('reduced_price', 'desc')
          ->get()
          ->result();
如何修改代码以实现此目的?

查询中的用例 $sql='当降价不为空时,按情况从产品订单中选择*,然后降价,否则价格结束'
$query=$this->db->query($sql);
返回$query->result_array()

类似这样的用例是sql查询

订购人 当降价不为空时,则降价结束,
如果降价为空,则价格结束

简单,只需检查第一个中的获取值,否则使用第二个,您也可以使用三元运算符最小化