Re: search script
| From: | Paul Chvostek | Date: | Mon, 24 Feb 2003 18:05:38 +0000 |
| Subject: | Re: search script | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136951@lists.php.net to get a copy of this message | ||
On Mon, Feb 24, 2003 at 12:40:45PM -0500, Bryan Brannigan wrote:
>
> 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?
Sure, depending on your database. In MySQL, you could use something
like the INSTR() function, making your query something like:
SELECT * FROM table
WHERE INSTR(fullname,'$fname') > 0 OR INSTR(fullname,'$lname') > 0;
or in PostgreSQL, which I believe doesn't have an INSTR function:
SELECT * FROM table
WHERE POSITION('$fname' in fullname) > 0
OR POSITION('$lname' in fullname) > 0;
And to make it case insensitive, wrap the options in LCASE or UCASE.
This sort of thing might be more likely to get a quick response on the
php-db list, and a more concise response if you include the type of
database you're using.
--
Paul Chvostek <paul@it.ca>
Operations / Abuse / Whatever
it.canada, hosting and development http://www.it.ca/