gpt4 book ai didi

php - Codeigniter事件记录和表别名

转载 作者:行者123 更新时间:2023-11-30 21:53:47 25 4
gpt4 key购买 nike

我正在尝试将计算出的SQL字段中的值作为别名从我的模型中检索到控制器中。 Codeigniter在视图中返回NULL,但是当我在Workbench中运行相同的查询时,得到了预期的结果。我的代码有什么地方做错了吗:
这是我的模特

public function get_balance() {
$this->db->select('SUM(IFNULL(transactions.credit,0)-IFNULL(transactions.debit,0)) AS clientBalance',FALSE);
$this->db->from('transactions');
$this->db->where('clientID', $this->uri->segment(3));
$this->db->group_by('accountID');
$query = $this->db->get();
return $query->row_array();
}


还有我的控制器

public function transactions($clientID = NULL) {
$data['client_balance'] = $this->accounts_model->get_balance();

$data['client_Balance'] = $data['client_balance']['clientBalance'];
}

最佳答案

尝试这个

public function get_balance() {
$this->db->select('SUM(IFNULL(transactions.credit,0)-IFNULL(transactions.debit,0)) AS clientBalance', FALSE);
$this->db->from('transactions');
$this->db->where('clientID', $this->uri->segment(3));
$this->db->group_by('accountID');
$query = $this->db->get();
$result = $query->row_array();
echo "<pre>".$this->db->last_query();
die;
return $result;
}



它将打印您的查询,然后与Workbench查询匹配
要么
在工作台中执行此打印查询


然后,您可以了解哪里出错了。

关于php - Codeigniter事件记录和表别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46083403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com