我的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