Re: Another question - not exactly what i was looking for
| From: | mike cullerton | Date: | Tue, 15 Jan 2002 21:18:39 +0000 |
| Subject: | Re: Another question - not exactly what i was looking for | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-80630@lists.php.net to get a copy of this message | ||
how 'bout something like
$query = 'select * from table_name where ';
$and = '';
if ($lastname != '') {
$query .= "lastname = $lastname";
$and = ' and ';
}
if ($firstname != '') {
$query .= $comma."firstname = $firstname;
$and = ' and ';
}
and so on
on 1/15/02 1:53 PM, Phil Schwarzmann at pschwar@jhmi.edu wrote:
> Yo, thanks for all your help. But it isn't exactly what im looking for.
>
> Let's say you had a database with the following four columns...
>
> -LastName
> -FirstName
> -Age
> -Weight
>
> ...and you wanted a page that would allow a user to search for one or
> more of these fields within the database.
>
> It would be easy if the user could only pick just one of the fields.
> But let's say that want to search only lastname and firstname, or maybe
> all four, or maybe just one. How could this be done?
>
> If I have code that looks like this...
>
> $query = "select * from table where lastname='$lastname' and
> firstname='$firstname' and age='$age' and weight='$weight'";
>
> $result = mysql_query ($query);
> $num_results = mysql_num_rows($result);
>
> ...the $num_results is ALWAYS zero unless I typed in all four fields.
>
> Any help?
>
> Thanks!
>
-- mike cullerton michaelc at cullerton dot com