Forum Moderators: open
Its fairly straight forward to search a db when theres only one possible way the user can search, what about when you have, lets say, 3 selects and a tick box?
How do you build a function for it? whats the correct method?
I have, for example, the following search facility, the first 3 are select boxes, last is a tick box.
location (where the user prefers)
start (when to start the holiday)
amount (how many people)
show part available (tick box can be ticked or left unticked)
The user, through javascript, MUST select start, but could select just that OR start & location, OR start, location & amount, or all PLUS the tick box, what road map do I need to follow to handle all possabilities?
[edit]using php[/edit]
Thanks as always
You just have to put your logic into some IFs, ANDs or ORs ...
Perhaps going like this ...
<?php
# validate all input variables
...
# prepare the SQL SELECT statement
$sql = '';
if (isset($start)) {
$sql = "select something from table where start='$start'";
if (isset($location)) {
$sql .= " and location='$location'";
}
if (isset($amount)) {
...
}
...
} # end IF start
# execute the $sql
...
?>
HTH and kind regards,
R.
Be aware, that it is important to validate your input variables before you start using them, otherwise you are at risk of your script being hacked, your data being stolen or damaged or compromised, and your server being 0wned (SQL injection).
Kind regards,
R.