Re: search script

From: Date: Mon, 24 Feb 2003 18:35:27 +0000
Subject: Re: search script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-136955@lists.php.net to get a copy of this message
At 18:40 24.02.2003, Bryan Brannigan spoke out and said: --------------------[snip]-------------------- >Ok, my problem of the day. I need to take a field from a form that has >either a first name, last name or both and then search the database for all >records that match one of those items. The problem, the database only has >one field for the name.. where both the first and last name are stored. > >Is there anyway I can do this? --------------------[snip]-------------------- $atokens = explode(' ', $_REQUEST['name']); $sql = null; foreach ($atokens as $name) $sql .= ($sql ? 'or ') . "name ilike '%$name%'"; $sql = 'select * from tablename where name ' . $sql; this is for PostgreSQL; for MySQL replace "ilike '%$name%'" with "INSTR(name,'$lname') > 0" Disclaimer: completely untested. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#136955) next »