gpt4 book ai didi

php - Codeigniter $this->db->select() 不适用于 Round(Max()) 或 FORMAT(MAX())

转载 作者:行者123 更新时间:2023-11-29 05:22:44 25 4
gpt4 key购买 nike

我写了下面的代码

$this->db->select('SUM(qty) as total_qty,(FORMAT(SUM(amount),2)) as total_amount');
$this->db->where('Invoice_Rec_No',$Invoice_Rec_No);
$result=$this->db->get($this->invoice_products_tbl);
$total_data=$result->row();

但出现错误

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (tbl_invoice_products) WHERE Invoice_Rec_No = 7' at line 2

SELECT SUM(qty) as total_qty, (FORMAT(SUM(amount), 2)) as total_amount FROM (tbl_invoice_products) WHERE Invoice_Rec_No = 7

Filename: C:\wamp\www\admin_followme247_master\system\database\DB_driver.php

我想用 codeigniter ActiveRecord 执行这​​个查询。

最佳答案

db select 方法中的用户第二个参数FALSE

    $this->db->select('SUM(qty) as total_qty,
(FORMAT(SUM(amount),2)) as total_amount', FALSE);

CI 数据库类在操作 sql 查询时自动添加 (撇号),如果您在 select` 方法中传递发送参数FALSE,则它与输入保持相同。








关于php - Codeigniter $this->db->select() 不适用于 Round(Max()) 或 FORMAT(MAX()),我们在Stack Overflow上找到一个类似的问题:

https://stackoverflow.com/questions/23822674/




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