【发布时间】:2017-07-19 15:45:22
【问题描述】:
我的 Sql 表
+------------+---------+
| name | price |
+------------+---------+
| A | 70 |
+------------+---------+
| B | 70 |
+------------+---------+
我用 TCPDF 创建一个 pdf:
$pdo = $db->prepare("SELECT * FROM table");
$pdo->execute();
while ($row = $pdo->fetch(PDO::FETCH_ASSOC)) {
$result += $row['price'];
}
$html = '
<table><tr><th>'.$result.'</th></tr></table>'
;
我希望结果是140,但我收到一条错误消息:
Notice: Undefined variable: result
TCPDF ERROR: Some data has already been output, can't send PDF file
注意:如果我删除 + 符号。 pdf 创建没有错误,我得到了结果70。
【问题讨论】:
-
使 $result = 0;在 $pdo->execute() 之后;现在你正试图向不存在的变量添加一些东西:)
标签: php mysql foreach tcpdf calculation