On Sun, 4 May 2008 21:37:19 +0000 (UTC), "aquas"
<webforumsuser@macromedia.com> wrote:
>The table I'm searching is apartment listings and the
checkboxes are bedrooms.
>So if a user wants to see 1 bedroom and 2 bedroom
apartments the results should
>show only 1 and 2 bedroom apartments. If nothing is
checked then it should show
>all the bedroom options (I guess that's the same as
checking all of them). All
>the values are found in the same field.
Is the bedrooms field in the database numeric or character?
Consider
this example which assumes the field is numeric:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Example</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>"
method="post">
<input type="checkbox" name="bedrooms[]" value="1" />
1<br />
<input type="checkbox" name="bedrooms[]" value="2" />
2<br />
<input type="checkbox" name="bedrooms[]" value="3" />
3<br />
<input type="checkbox" name="bedrooms[]" value="4" />
4<br />
<input type="submit" />
</form>
<?php
$sql='SELECT * FROM apartments';
if(is_array($_POST['bedrooms'])){
$bedrooms=join(',',$_POST['bedrooms']);
$sql.=" WHERE bedrooms IN ($bedrooms)";
}
print "<p>$sql</p>\n";
?>
</body>
</html>
Gary