Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.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 CodeIgniter3 order_by()如何在活动记录中最后使用空值_Php_Postgresql_Codeigniter 3 - Fatal编程技术网

Php CodeIgniter3 order_by()如何在活动记录中最后使用空值

Php CodeIgniter3 order_by()如何在活动记录中最后使用空值,php,postgresql,codeigniter-3,Php,Postgresql,Codeigniter 3,我将Potgresql与Codeigniter一起使用,我的查询在需要用于order\u by()的列中返回空值。正如我在很多例子中看到的那样,我在SO和google上发现它们都不起作用。 当我在pgAdmin中尝试此查询时,它可以工作,并在最后一位输入空值 SELECT a.*, b.*, c.* FROM accounts a LEFT JOIN subscriptions b ON a.id = b.provider_account_id AND b.subscriber_account_

我将Potgresql与Codeigniter一起使用,我的查询在需要用于
order\u by()
的列中返回空值。正如我在很多例子中看到的那样,我在SO和google上发现它们都不起作用。 当我在pgAdmin中尝试此查询时,它可以工作,并在最后一位输入空值

SELECT a.*, b.*, c.*
FROM accounts a
LEFT JOIN subscriptions b ON a.id = b.provider_account_id AND b.subscriber_account_id = 10
JOIN users c ON c.email = a.name
WHERE a.user_role = 0
ORDER BY b.following DESC NULLS LAST, b.last_updated DESC NULLS LAST;
这是Codeigniter中模型中的查询,它将空值放在第一位

$this->db->select('a.*, b.*, c.*');
$this->db->from('accounts a');
$this->db->join('subscriptions b', 'a.id = b.provider_account_id AND b.subscriber_account_id = '.$client_id, 'left');
$this->db->join('users c', 'c.email = a.name');
$this->db->where('a.user_role', 0);
$this->db->order_by('b.following', 'desc');
$this->db->order_by('b.last_updated', 'desc');

因此,我如何在
order\u by()中实现
NULLS LAST
函数

已解决

修改了“system/database/DB\u query\u builder.php”中的
order\u by()
函数

改变

$direction = in_array($direction, array('ASC', 'DESC'), TRUE) ? ' '.$direction : '';

现在我可以像这样使用它了

$this->db->order_by('column', 'desc nulls first');
$this->db->order_by('column', 'desc nulls last');
$this->db->order_by('column', 'asc nulls first');
$this->db->order_by('column', 'asc nulls last');
$this->db->order_by('column', 'desc nulls first');
$this->db->order_by('column', 'desc nulls last');
$this->db->order_by('column', 'asc nulls first');
$this->db->order_by('column', 'asc nulls last');