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/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to