【发布时间】:2018-12-17 03:28:26
【问题描述】:
我只是跳入 codeigniter,我认为在 Model 和 Controller 中学习很难,但 Viewes 很好。我面临在codeigniter中创建计算(添加+)函数的问题。
实际上,在我的数据库中,我保存了这样的值:-
-------------------------------------------
ID | Name | Amount | DATE
-------------------------------------------
01 | Product 1 | $250 | 20/09/1996
02 | Product 2 | $200 | 20/09/1996
03 | Product 3 | $210 | 20/09/1996
04 | Product 4 | $260 | 20/09/1996
05 | Product 5 | $280 | 20/09/1996
我想添加所有金额值,以便我创建此代码并添加到模型中
public function countTotalToday()
{
date_default_timezone_set('Asia/Mumbai');
$now = date('d-m-Y');
//$sql = "SELECT amount FROM orders_item WHERE date = '$now'";
$sql = "sum(amount) from order_item where date(dateCol)=date(now())";
$query = $this->db->query($sql);
//return $query->num_rows();
}
在控制器中我是这样的
$this->data['total_paisa'] = $this->model_brands->countTotalToday();
在视图中
<h3 style="display:inline;"><?php echo $total_paisa ?></h3><h5 style="display:inline; vertical-align:center;">(Sleep <?php echo $total_paisa ?>)</h5>
但代码显示错误 500,我不知道我已解决此问题,您能否帮我制作用于计算金额的代码,并在添加方法中计算的视图中回显我。
【问题讨论】:
-
“不工作”是什么意思?你有任何错误吗?在您的文件顶部添加error reporting:
ini_set("display_errors", 1); error_reporting(E_ALL);并告诉我们您得到了什么。 -
在 codeigniter 中我编辑您的代码以显示错误,我上面的代码是否正确?
-
arjunphp.com/error-reporting-handling-in-codeigniter(另外,请不要全部输入大写。这表示你在大喊大叫,这不是你想对试图帮助你的用户做的事情)跨度>
-
您的表中没有
date列。那么为什么要在where条件下使用它呢? -
很抱歉,我忘记在帖子中更新日期,但我确实在数据库中
标签: php codeigniter calculation