gpt4 book ai didi

php - 在 OpenCart 中显示表中列的总和

转载 作者:行者123 更新时间:2023-11-29 18:39:45 24 4
gpt4 key购买 nike

我在 OpenCart 工作,不习惯 MVC 或 PHP 。我正在尝试从表中获取列的总和并将其显示在模板文件中。我很难设置它。我不明白如何设置控件我认为我已经正确设置了模型。型号:

    // sum of all rows in a column(amount) from a table
public function getSum() {
$amount_total = $this->db->query(‘SELECT SUM(amount) as amount_sum FROM table’);
$row = mysql_fetch_assoc($amount_total);
$sum= $row[‘amount_sum’];

return $sum;
}

控制:

$total_amount = $this->model_order->getSum();
$this->data['amount_total'] = array(got lost here, maybe not an array?);
//not sure how to finish control
//not sure how to pass to view

查看://在 tpl 文件中我是否只执行这样的 php 语句?:

<?php echo $amount_total; ?>

任何帮助都会很棒,我一直在尝试在这里和其他地方找到的不同东西,但我只是变得更加困惑。

最佳答案

如果您没有使用 opencart 的 MVC,那么如何在脚本中使用模型。

但是如果您以任何方式使用该模型,那么您需要将这些行替换为

$row = mysql_fetch_assoc($amount_total);$sum= $row['amount_sum'];

$sum=$amount_total->row['amount_sum'];

希望它对你有用。

关于php - 在 OpenCart 中显示表中列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45025377/

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