我得到這個錯誤在我的劇本,我認爲是造成搜索欄不工作:致命錯誤導致沒有結果出現(mysqli的)
Fatal error: Call to a member function bind_param() on a non-object in /web/stud/xxx/Mobile_app/previousquestions.php on line 89.
線它指向的就是這條線:
$stmt->bind_param("s",$each);
需要做什麼才能解決這個錯誤?此時,錯誤導致用戶在搜索欄內提交內容後不會顯示任何結果。
<?php
//connect to db
$questioncontent = (isset($_POST['questioncontent'])) ? $_POST['questioncontent'] : '';
?>
<?php
if (isset($_GET['searchQuestion'])) {
$searchquestion = $questioncontent;
$terms = explode(" ", $searchquestion);
$parameters = array();
$questionquery = "
SELECT q.QuestionId, q.QuestionContent, o.OptionType, q.NoofAnswers, GROUP_CONCAT(an.Answer ORDER BY an.Answer SEPARATOR ' ') AS Answer, r.ReplyType,
q.QuestionMarks
FROM Answer an
INNER JOIN Question q ON q.AnswerId = an.AnswerId
JOIN Reply r ON q.ReplyId = r.ReplyId
JOIN Option_Table o ON q.OptionId = o.OptionId
WHERE ";
$i=0;
foreach ($terms as $each) {
$i++;
if ($i == 1){
$questionquery .= "q.QuestionContent LIKE ?";
} else {
$questionquery .= "OR q.QuestionContent LIKE ?";
}
}
$questionquery .= "GROUP BY q.QuestionId, q.SessionId ORDER BY "; $i = 0; foreach ($terms as $each) {
$i++;
if ($i != 1)
$questionquery .= "+";
$questionquery .= "IF(q.QuestionContent LIKE ?,1,0)";
}
$questionquery .= " DESC ";
$stmt=$mysqli->prepare($questionquery);
$parameters[] = ($each)
$stmt->execute($parameters);
$stmt->bind_result($dbQuestionId,$dbQuestionContent,$dbOptionType,$dbNoofAnswers,$dbAnswer,$dbReplyType,$dbQuestionMarks);
$questionnum = $stmt->num_rows();
}
?>
你有沒有想過[全文搜索](http://dev.mysql.com/doc/refman/5.6/en/fulltext-search.html)? – Gumbo
@Gumbo我通過使用mysql在問題中查找關鍵字來創建一個像小搜索引擎。 – user1394925
通過全文搜索,所有這些都將由MySQL完成。 – Gumbo