I suspect you would want to do something along the lines of:
<form action="categories.php" method="GET">
<fieldset>
<legend>Filter Categories</legend>
<p>
<label><input type="checkbox" name="categories[]" value="music"/> Music</label>
<label><input type="checkbox" name="categories[]" value="technology"/> Technology</label>
<label><input type="checkbox" name="categories[]" value="film"/> Film</label>
</p>
</fieldset>
<button type="submit">Filter</button>
<button type="reset">Reset</button>
</form>
When submitted, this will give you a URL such as the following:
http://example.com/categories.php?categories[]=music&categories[]=technology
Then, in the script that displays the matching entries having one of these categories, you could do the following with the WHERE
clause:
$get_categories = $_GET['categories'];
$cat_clauses = array();
while ($category = array_shift($get_categories)) {
// Clean it
$category = preg_replace('/[^a-z0-9-_]/i', '', $category);
if ($category) {
array_push($cat_clauses, "OR category LIKE '%$category%'");
}
}
if ($cat_clauses) {
$cat_where = "AND (" . implode(' ', $cat_clauses) . ")";
}
Which might give you something like:
SELECT *
FROM blog
WHERE active = 1
AND (category LIKE '%technology%' OR category LIKE '%music%')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…