Re: Problem with searching in database
| From: | Koos van den Hout | Date: | Wed, 13 Sep 2000 07:56:04 +0000 |
| Subject: | Re: Problem with searching in database | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-2858@lists.php.net to get a copy of this message | ||
Quoting Daniel Rezny who wrote on Wed, Sep 13, 2000 at 09:08:11AM +0200:
> if($birthy != "")
> {
> $query= "select id,birthdatum,todesdatum,nachname,vorname from doew where
> birthdatum like '%$birthy%'";
> }
> elseif($diey != "")
> {
> $query= "select id,birthdatum,todesdatum,nachname,vorname from doew where
> todesjahr like '%$diey%'";
> }
> Everithing working correct if I want to search only by one field. If I
> want to search by more fields it search only by the first one. I use
> this script on linux+php3+mysql and working correctly. Do somebody
> know why it is.
Because that is *exactly* what your code does ? It checks for the first
variable and then only if it that isn't found checks for the second.
If you want to search on multiple criteria, you'll have to adjust the sql
query accordingly.
Something like building an array of constraints "todesjahr like '%$diey'"
and then connecting them to one query select .. where + constraints linked
by ' and '. You'll have to do some array magic.
Koos van den Hout
--
Koos van den Hout, PGP keyid RSA/1024 0xCA845CB5 via keyservers
koos@kzdoos.xs4all.nl or DSS/1024 0xF0D7C263 -?)
Fax +31-30-2817051 Visit my site about books with reviews /\\
http://idefix.net/~koos/ http://www.virtualbookcase.com/ _\_V