我從窗體發送一個值的數組。我想遍歷數據庫表尋找這些ID。當我得到這個消息我明白了什麼是錯的...MySQLi foreach bind_param()
致命錯誤:調用一個成員函數bind_param()一個非對象在/home/d15155/tool/pdf.php在線56
if (count($_POST['q']) == 0){
}
else {
foreach($_POST['q'] as $quality){
# Prepare statement
$stmt = $mysqli->prepare("SELECT the_question, the_sub_questions, the_quality, the_time FROM my_questions WHERE the_category='2' AND the_headline='5' AND quality_id = ? ORDER BY the_sort_order ASC");
$stmt->bind_param('i', $quality);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($the_question, $the_sub_questions, $the_quality, $the_time);
$stmt->fetch();
$konkretaexempel .= utf8_encode($the_question) . " <br />";
}
}
我想將結果添加到一個長字符串(然後在PDF中使用)。
EDIT
刪除了的foreach和陣列,它仍然得到同樣的錯誤消息。我已檢查並且數據庫連接正常。
if (count($_POST['q']) == 0){
}
else {
$stmt = $mysqli->prepare("SELECT the_question, the_sub_questions, the_quality, the_time FROM my_questions WHERE the_category='2' AND the_headline='5' AND quality_id = ? ORDER BY the_sort_order ASC");
$stmt->bind_param('i', '27');
$stmt->execute();
$stmt->bind_result($the_question, $the_sub_questions, $the_quality, $the_time);
$stmt->fetch();
$konkretaexempel .= utf8_encode($the_question) . " <br />";
}
它看起來像你截斷了錯誤信息;您可能需要編輯您的問題以包含完整的訊息。 –
這意味着'準備'不起作用。嘗試在你的語句中添加\'aroung列名 – Random
注意:' - > prepare()'的目的是讓你不必在每次循環迭代時調用它。通過將它放入你的'foreach()'中,你正在浪費其最好的功能/特性之一。 – Sean