[英]SQL query using checkboxes
我在這里看到了有關此主題的一些問題,但沒有一個問題解決了我的問題。 我正在嘗試使用SQL和復選框創建一個簡單的過濾器。
到目前為止,我得到了以下代碼:
<form action="#" method="GET" id="filter">
<input type="checkbox" name="omgeving[]" value="Indoor">Indoor<br />
<input type="checkbox" name="omgeving[]" value="Outdoor">Outdoor<br />
<input type="submit" name="kies" value="Kies" />
</form>
<?php
if(isset($_GET['omgeving']) && count($_GET['omgeving'] > 0)) {
$catid = implode(',', $_GET['omgeving']);
$catid = mysql_real_escape_string($catid);
$query = mysql_query("SELECT * FROM SomeWhere WHERE Omgeving IN (".$catid.")");
while($row = mysql_fetch_assoc($query)) {
$id = $row['Id'];
$prod = $row['Product'];
echo $prod . "<br />";
}
}
?>
當我單擊“ submit
時,它執行了一些操作 ,將URL更改為: filtertest/?omgeving[]=Indoor&kies=Kies
但我認為查詢無法正常工作,因為頁腳通常消失了,這意味着我的代碼不正確,並且頁面停止進一步加載。 為了我的愛,我不知道為什么這不起作用...
有沒有人可以幫助我?
我已經簽出了這個答案,但這不能解決我的問題。 上面的代碼至少可以執行某些操作。
求助...我在這里做錯了什么?
將omgeving[]
更改為omgeving
。 因此,URL為?omgeving=Indoor&kies=Kies
<?php
if(isset($_GET['omgeving']) || !empty($_GET['omgeving'])){
$catid = mysql_real_escape_string($_GET['omgeving']);
//continue with what you are doing.
// use var_dump(<variable>); exit(); to debug.
}
?>
希望對您有所幫助!
換線
$catid = implode(',', $_GET['omgeving']);
至
$catid = implode('","', $_GET['omgeving']);
$catid = '"'.$catid.'"';
最后,如果您選擇了多個查詢,則查詢應如下所示
SELECT * FROM從何處進入(“室內”,“室外”)
$ catid = implode(“','”,$ _GET ['omgeving']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.