2
我有这个音乐网站,我有一个搜索侧栏,我希望人们能够从我的表中找到正确的音乐家个人资料。搜索表单使用复选框构建,并使用PHP和MySQL连接到我的表格。我希望人们能够从类别中找到配置文件,例如位置,用户类型,他们播放的音乐流派以及是否有专辑发布。查询搜索与多个复选框名称
<form action="udforsk.php" method="post" enctype="multipart/form-data">
<h2>User type</h2>
<input type="checkbox" name="type[]" value="Solo">
<input type="checkbox" name="type[]" value="Duo">
<input type="checkbox" name="type[]" value="Band">
<h2>Location</h2>
<input type="checkbox" name="location[]" value="area_1">
<input type="checkbox" name="location[]" value="area_2">
<input type="checkbox" name="location[]" value="area_3">
<input type="checkbox" name="location[]" value="area_4">
<input type="checkbox" name="location[]" value="area_5">
<h2>Genre</h2>
<input type="checkbox" name="genre[]" value="genre_1">
<input type="checkbox" name="genre[]" value="genre_2">
<input type="checkbox" name="genre[]" value="genre_3">
<input type="checkbox" name="genre[]" value="genre_4">
<input type="checkbox" name="genre[]" value="genre_5">
<h2>Album or demo</h2>
<input type="checkbox" name="release[]" value="album">
<input type="checkbox" name="release[]" value="demo">
</form>
我希望这被连接到一个查询宽度,但我有问题如何处理一些类别没有被填写的搜索。如果没有选中地点复选框,则查询搜索中所有地点都是公平的游戏。
现在我试图用IN来搜索用户,我的查询看起来像这样,但当$ _POST输入为空时,它给我带来麻烦。现在我只是试图使它与地点和流派合作。
$sql = "SELECT artist.ArtistID, artist.ArtistName, artist.RegionID,
artist_genre.ArtistID, artist_genre.GenreID
FROM artist, artist_genre
WHERE artist.RegionID IN ($areaer) AND artist_genre.GenreID IN ($genrer)";
所有帮助如何使用多个搜索变量与多个搜索变量一般复选框将是很多的帮助。
[PHP:检查是否有任何张贴的变量是空的](https://stackoverflow.com/questions/3190464/php-check-if-any-posted-vars-are-empty-form-all-fields-required ) –
[检查$ _POST-value是否为空](https://stackoverflow.com/questions/9154719/check-whether-post-value-is-empty) –
如果你想有一个默认值,你可以使用输入类型=“隐藏”,所以如果没有勾选它会发布默认值 –