Lana:
The easiest thing would be if your field always contained the same
number of comma-separated strings. Then you could just do something
like a SUBSTRING_INDEX() function to break out the field into separate
values. But, assuming your field does not always contain the same
number of strings...
I'm imagining the contents of <field1> look like "abc,def,ghi". You
want to do:
SELECT FUNCTION_NAME( field1 )
and get back
Row1: abc
Row2: def
Row3: ghi
If that's right, off the top of my head you have two options. The first
option I can think of would be to break out these values into another
table. Instead of a comma-separated list inside a field, move that
field to another table and break each value into it's own record,
linked back to the parent table by ID. A quick search of the list
archives will bring up better descriptions on how to normalize than I
could give.
The other, possibly simpler, option is to handle it in PHP. You could
just grab the field, containing a list of strings delimited by commas,
and use the explode() function to get your results. The PHP site has
plenty of examples on the usage of explode.
http://us2.php.net/explode
Wes
On Jun 30, 2004, at 5:35 PM, L a n a wrote:
> Hello,
> Im working on a search function using PHP4 and MYSQL4.
>
> Im looking for a function that allow to take a string value
> (consisted of several substrings separated by coma) out of db field
> and return each substring one by one.
>
> Could you please tell me if there is a function that can do something
> similar to
>
> SELECT function_name (field_name, ,)
> (return)-> substr1, substr2, substr3
>
>
> Thank you for your help,
> Lana
>
> _________________________________________________________________
> Add photos to your messages with MSN Premium. Get 2 months FREE*
> http://join.msn.com/?pgmarket=en-ca&page=byoa/
> prem&xAPID=1994&DI=1034&SU=http://hotmail.com/
> enca&HL=Market_MSNIS_Taglines
>
>
>