【发布时间】:2016-03-02 13:21:48
【问题描述】:
我想将复选框与我的 SQL 选择语句集成,但我不确定如何将数组转换为可用的选择。
<form method="post">
<input name="searchterm" type="search" placeholder="Enter Search Terms Here" />
<input name="searchbtn" type="submit" value="Karaoke Search" />
<input name="checkbx[]" type="checkbox" checked value="Chartbuster" />
<label>Chartbuster</label>
<input name="checkbx[]" type="checkbox" checked value="Sound Choice" />
<label>Sound Choice</label>
<input name="checkbx[]" type="checkbox" checked value="DKKaraoke" />
<label>DKKaraoke</label>
<input name="checkbx[]" type="checkbox" checked value="Sunfly" />
<label>Sunfly</label>
<input name="checkbx[]" type="checkbox" checked value="Karaoke Hits" />
<label>Karaoke Hits</label>
<?php
if(isset($_POST['searchterm']) and ($_POST['searchterm']!="")) {
$searchterm=$_POST['searchterm'];
$checkbx=$_POST['checkbx'];
$searchresults=$db->query("SELECT *
FROM 1KaraokeDJ
WHERE Artist LIKE '%$searchterm%'
GROUP BY Artist,
Title,
Brand
ORDER BY Artist,
Title,
Disc LIMIT 100");
}
...
?>
...
</form>
基本上,将搜索限制在所选复选框之一中的品牌位置
【问题讨论】:
-
只使用mysql IN() 语句,如 Brand IN (join(',', $checkbx)) link (stackoverflow.com/questions/907806/…)
-
SELECT * FROM 1KaraokeDJ WHERE Artist LIKE '%$searchterm%' AND Brand IN (join(',',$checkbx)) GROUP BY Artist, Title, Brand ORDER BY Artist, Title, Disc LIMIT 100 - 不产生任何结果
-
$checkbx = join(',',$checkbx); plus AND Brand IN $checkbx 也不会产生任何结果 - s