Re: Query question about how to do a select which returns things that resemble the input

From: Date: Tue, 20 Jun 2000 17:29:25 +0000
Subject: Re: Query question about how to do a select which returns things that resemble the input
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-2329@lists.php.net to get a copy of this message
>> 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? > > Use the LIKE operator in the select statement: > > "select * from table where field like '%$search_string%';" Note that this would only work for the first 2 of those three example cases. For less precise matching, things become much, much more complicated. If you're using something like Oracle with Context or DB/2 with its plain-text matching (TextBlade?) those functions will probably give the most accurate results unless your queries can be restricted tightly enough. With something like MySQL, your options a bit limited. One approach would be the use of SOUNDEX() but that's really only going to work for individual words. If you can come up with some way of generating regular expressions that match your target, you can use MySQL's regular expression support (http://www.mysql.com/Manual_chapter/manual_Tutorial.html#Pattern_matching).

« previous php.general (#2329) next »