Forums
 This topic is locked 
             SQL Query any value
 Posted 10 Feb 2002  14:18:29 
  1 
     has   voted 
  10 Feb 2002  14:18:29 Ryan Schwiebert posted: 
 How do I write an sql where statement to retrieve any possible value?  I have a search page where you can select from a drop down list the number of bedrooms in a house. (values are 1, 2, 3, & 4) I want to add one to the list that searches for 'All bedrooms'
How should the sql look to retrieve results for all bedroom numbers? What value do I place in the drop downlist for "Any/All"? I thought it would be '%' but that returns an error.
I know I can do this much:
SELECT *
FROM rentals
WHERE bedrooms = $HTTP_POST_VARS["bedrooms"]
ORDER BY cabinname ASC
Any help is appreciated!
--
Ryan
Replies
 Replied 03 Mar 2002  16:59:01 
   03 Mar 2002  16:59:01 Stephen Bateman replied: 
  Hi ryans,
I do my queries like this:
<?php
if (($HTTP_POST_VARS["bedrooms"] == "All"
 or ($HTTP_POST_VARS["bedrooms"] == ""
)
{
$filter = "";
}
else
{
$filter = "WHERE bedrooms = ";
$filter .= $HTTP_POST_VARS["bedrooms"];
}
SELECT * FROM rentals $filter ORDER BY cabinname ASC
?>
Hope that helps.
Stephen
Edited by - GreatTraveller on 03 Mar 2002 17:00:28
  I do my queries like this:
<?php
if (($HTTP_POST_VARS["bedrooms"] == "All"
{
$filter = "";
}
else
{
$filter = "WHERE bedrooms = ";
$filter .= $HTTP_POST_VARS["bedrooms"];
}
SELECT * FROM rentals $filter ORDER BY cabinname ASC
?>
Hope that helps.
Stephen
Edited by - GreatTraveller on 03 Mar 2002 17:00:28