Re: filter search
| From: | Jim Giner | Date: | Tue, 19 Apr 2011 13:45:27 +0000 |
| Subject: | Re: filter search | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-47766@lists.php.net to get a copy of this message | ||
First - I would change "day,month,year" to a date field called 'birthdate'.
Then on the screen that the user chooses what to search for you let them
enter 1 or 2 or 3 values: the 'name', the 'city' or the 'age' (in
years).
Then when you process that input, you determine what they entered - 1 or 2
or 3 things and build a WHERE clause based on 1 or 2 or 3 things.
For the Age filter you take it and subttract it from today's date (call it
'filterdate') and use the resulting date to say "birthdate >= filterdate"
Once you have your where clause built, you build your query and add the
where clause to it, like this:
$query = "SELECT * FROM $mydatabase WHERE $my_where_clause ORDER BY id DESC"