RE: [PHP-DB] Query question about how to do a select which return s things that resemble the input
| From: | Nold, Mark | Date: | Wed, 21 Jun 2000 01:54:01 +0000 |
| Subject: | RE: [PHP-DB] Query question about how to do a select which return s things that resemble the input | ||
| Groups: | php.db php.general | ||
| Request: | Send a blank email to php-general+get-2427@lists.php.net to get a copy of this message | ||
----------------------------------------------------------------------------
-----------------
Disclaimer: The information contained in this email is intended only for the
use of the person(s) to whom it is addressed and may be confidential or
contain legally privileged information. If you are not the intended
recipient you are hereby notified that any perusal, use, distribution,
copying or disclosure is strictly prohibited. If you have received this
email in error please immediately advise us by return email at
postmaster@normandy.com.au and delete the email document without making a
copy.
----------------------------------------------------------------------------
-----------------
Maarten,
I would suggest you break down Terdam into segments of varying length. I got
a bit carried away so i attched a function and an example.
It should result in something like;
SELECT
*
FROM
mytable
WHERE
afield = 'foo' and
anotherfield = 'bar' and
(
LOWER(myfield) like '%terdam%' OR
LOWER(myfield) like '%terda%' OR
LOWER(myfield) like '%erdam%' OR
LOWER(myfield) like '%terd%' OR
LOWER(myfield) like '%erda%' OR
LOWER(myfield) like '%rdam%' OR
LOWER(myfield) like '%rda%' OR
LOWER(myfield) like '%erd%' OR
LOWER(myfield) like '%dam%' OR
LOWER(myfield) like '%ter%'
)
Now you may find it better for your db to do the matches in the reverse
order (change the arsort() to asort() as everything that has terdam will be
retrieved by ter etc. Im guesing but an optimiser may find this...
You may want to improve the function so that terdam, terda, erdam, terd,
rdam are discarded... but i wouldnt as they help with scoring matches.
The big challange is once you've brought them back how do you score them
based on their matching? (See the attachment for how id go about it.)
If you have some more ideas ideas i'd love to see them as i see this being
pretty useful.
mn
-----Original Message-----
From: Boaz Yahav [mailto:berber@netvision.net.il]
Sent: Tuesday, June 20, 2000 8:54 PM
To: 'Maarten Stolte'; 'php3@lists.php.net'; php-general@lists.php.net;
php-db@lists.php.net
Subject: RE: [PHP-DB] Query question about how to do a select which
return s things that resemble the input
Use LIKE
SELECT * FROM MyTable WHERE MyField LIKE '%MyWord%'
Sincerely
berber
Visit http://www.weberdev.com Today!!!
To see where PHP might take you tomorrow.
-----Original Message-----
From: Maarten Stolte [mailto:M.Stolte@Samhoud.nl]
Sent: Tuesday, June 20, 2000 10:48 AM
To: 'php3@lists.php.net'; php-general@lists.php.net; php-db@lists.php.net
Subject: [PHP-DB] Query question about how to do a select which returns
things that resemble the input
Hi,
I'd like to know how to return some possibilities based on
a users input, e.g:
The users input is "terdam", and the db returns 'rotterdam,amsterdam,tordam'
How do i do this?
Maarten
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
For additional commands, e-mail: php-db-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net