Re: searching by _'s problem :(
| From: | Daniel Convissor | Date: | Sat, 02 Dec 2000 16:51:43 +0000 |
| Subject: | Re: searching by _'s problem :( | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28373@lists.php.net to get a copy of this message | ||
Sire
> $srch = str_replace('
> ','',str_replace('.','',$srch));
This works fine for me.
> $srch = "%".$search."%";
You need to use the right variable here. You've mistakenly used "$search"
rather than "$srch"
Please note, why are you placing %'s around your postal code? If you're
using MySQL, and probably other databases, placing a % _before_ the search
term will eliminate the use of indexes, which will dramatically slow down
your searches. Also, I hope you have the postal code stored in a separate,
indexed, field in your database -- as opposed to storing the postal code in
the same field as the address, city and/or country. Again, for speed
purposes. Thus, if you properly design your database, you won't need the %
before or after your postal code.
> Also, english postcodes are like: AA1 5AA . Even if i convert it to
> "AA15AA", what I need to do is put 3d and 4th letters as wildcards
> ("_" in sql i hear). But how can I if its a variable ??? :((
There are lots of ways to do this. Here's the simplest:
$srch = substr("$srch", 0,2) . "__" . substr("$srch", 4,2);
Enjoy,
--Dan
--
PHP scripts that make your job easier
http://www.analysisandsolutions.com/code/
SQL Solution | Layout Solution | Form Solution
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409