Re: where match question
| From: | Németh Zoltán | Date: | Tue, 23 Jan 2007 08:51:15 +0000 |
| Subject: | Re: where match question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247620@lists.php.net to get a copy of this message | ||
On k, 2007-01-23 at 19:46 +1100, chris smith wrote:
> On 1/23/07, Németh Zoltán <znemeth@alterationx.hu> wrote:
> > On h, 2007-01-22 at 22:53 -0800, Jim Lucas wrote:
> > > Don wrote:
> > > > I have a db field that contains zip codes separated by comas.
> > > >
> > > > I am trying to get php to return all of the rows that contain a particular
> > > > zip code.
> > > >
> > > >
> > > >
> > > > $query = "SELECT * FROM info WHERE MATCH (partialZIP) AGAINST
> > > > ('$zip')";
> > >
> > > try this
> > >
> > > $query = "SELECT * FROM info WHERE column LIKE '{$zip}'";
> >
> > I would use
> >
> > $query = "SELECT * FROM info WHERE LOCATE('{$zip}', column) > 0";
>
> And how are you going to index that? That's going to be extremely slow
> as the size of the table grows.
>
well, yes.
better solution is to not store the zip codes in one field with commas,
but in a separate table which relates to this one. and then you could
use a query like
$query = "SELECT t1.*, t2.* FROM info t1, zips t2 WHERE t1.id=t2.infoid
AND t2.zip = '{$zip}'";
greets
Zoltán Németh