Re: regexp with mysql
| From: | CPT John W. Holmes | Date: | Thu, 15 Jan 2004 16:09:14 +0000 |
| Subject: | Re: regexp with mysql | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-174672@lists.php.net to get a copy of this message | ||
How about:
SELECT * FROM table WHERE FIND_IN_SET(2,column);
where "column" is your table column containing the comma separated list.
---John Holmes...
----- Original Message -----
From: "Toby Irmer" <php@irmer.com>
To: "Lowell Allen" <la@lowellallen.com>; "PHP"
<php-general@lists.php.net>
Sent: Thursday, January 15, 2004 10:48 AM
Subject: Re: [PHP] regexp with mysql
> i guess
>
> SELECT * FROM
table WHERE ids REGEXP ',2,|^2,|,2$'
>
> should do it...
>
> hth
>
> toby
>
>
> ----- Original Message -----
> From: "Lowell Allen" <la@lowellallen.com>
> To: "PHP" <php-general@lists.php.net>
> Sent: Thursday, January 15, 2004 4:39 PM
> Subject: Re: [PHP] regexp with mysql
>
>
> > > i hope someone can help it should be easy but i still don't get it.
> > >
> > > i have a field which has numbers seperated via a comma
> > > for example 1,2,3,12,14,23,51
> > >
> > > now if i was to do a search for a the rows that has '2' in it i do
> > > SELECT * FROM table WHERE ids REGEXP "2"
> > >
> > > will it show fields that has 12 22 23 etc...?? or just 2
> >
> > Yes. I think you need something like:
> >
> > $sql = "SELECT * FROM table WHERE ".
> > "ids REGEXP '2' AND ids NOT REGEXP
> > '([1-9]2)|(2[0-9])'";
> >
> > But I don't profess to much knowledge of regular expressions. Check the
> > MySQL documentation. I saw something about REGEXP there recently. Also,
> > there's a MySQL discussion list at
> > <http://lists.mysql.com/>.
> >
> > HTH
> >
> > --
> > Lowell Allen
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>