我絕對掙扎與jQuery。 本質上,我有一個搜索欄,它查詢我的數據庫,並動態地填充下拉框與相關搜索(像任何像樣的搜索欄。)與jQuery和PHP填充數組
無論如何,我其實不知道如何讓用戶點擊元素將數據添加到數組中。現在,它只是
echo '<a href="index.php?action='.$result->game_id.'">';
這個工程,但我希望能夠讓用戶從搜索欄中選擇多個東西。
如果任何人都可以發佈一些代碼,或指向一個教程來幫助我弄清楚這個可怕的事情。
謝謝。
[編輯]
對不起,我不認爲我很清楚,並感謝對整個jquery的自動完成功能的信息,但我已經有了!
if(isset($_POST['queryString'])) {
$queryString = mysqli_real_escape_string($GLOBALS["___mysqli_ston"],$_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
$query = mysqli_query($GLOBALS["___mysqli_ston"],"SELECT * FROM gamelist WHERE name LIKE '%" . $queryString . "%' LIMIT 8");
if($query) {
// While there are results loop through them - fetching an Object.
while ($result = $query ->fetch_object()) {
echo '<a href="index.php?action='.$result->game_id.'">';
echo "<img src = ".$result->image_thumb." height=46 width=46 />";
$name = $result->name;
echo '<span class="searchheading">'.$name.'</span>';
$description = $result->aliases;
if(strlen($description) > 80) {
$description = substr($description, 0, 80) . "...";
}
echo '<span>'.$description.'</span></a>';
}
echo '<span class="seperator"><a href="http://www.marcofolio.net/sitemap.html" title="Sitemap">Nothing interesting here? Try the sitemap.</a></span><br class="break" />';
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
正如你所看到的,當我通過彥博得到一個輸入,只有這樣我可以有一個用戶與結果交互是點擊一個HREF鏈接。我想我只問,什麼是一些讓我允許用戶單擊它的jQuery代碼,並將它存儲回_POST []數組中?這樣我可以讓他們將多個搜索項存儲到數組中,以便我的PHP代碼可以對它進行評估。
我希望更清楚。
這裏沒有足夠的信息給你一個體面的答案。你可以發佈你現在擁有的樣本,並且更好地描述你有什麼問題嗎? – Brad
jQuery UI有一個名爲「自動完成」的小部件,可以幫助你做到這一點。您指定搜索的來源,它可以是一個AJAX端點 - 對您的PhP腳本的標註。然後,jQuery的自動完成功能會自動顯示下拉框,並讓用戶通過列表光標,或者單擊選擇。它很好地工作。例如:http://jsbin.com/ezifi – Cheeso