well this is simple and a little hard.
i receive data from a form like
$name
$email
$city
$state
etc
and i need to join all into a mysql query like:
$sql = "SELECT * FROM users WHERE name = 'value' AND email = 'value'";
but some times the information can came without data. i was thinking about something like this:
$sql = "SELECT * FROM users WHERE";
if ($name ne '') {
$sql .= " name = '$name'";
}
But how can i know if i will need 'AND' or not.
mean how can i know what was the last field incresed and if it got no AND and if the others got AND.
example
name = '' AND email = '' AND lastfield = '' ORDER BY name";
as u can see last field has no AND
any ideas please.
i receive data from a form like
$name
$city
$state
etc
and i need to join all into a mysql query like:
$sql = "SELECT * FROM users WHERE name = 'value' AND email = 'value'";
but some times the information can came without data. i was thinking about something like this:
$sql = "SELECT * FROM users WHERE";
if ($name ne '') {
$sql .= " name = '$name'";
}
But how can i know if i will need 'AND' or not.
mean how can i know what was the last field incresed and if it got no AND and if the others got AND.
example
name = '' AND email = '' AND lastfield = '' ORDER BY name";
as u can see last field has no AND
any ideas please.