我的SQL表为什么我的变量在TCPDF中未定义?
+------------+---------+
| 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
。
make $ result = 0;在$ pdo-> execute()之后;现在你试图添加一些不存在的变量:) – barat
[PHP:“注意:未定义的变量”,“注意:未定义的索引”和“注意:未定义的偏移量”)(http:// stackoverflow .com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – miken32