Matthew Stuart wrote:
> I have a DB that has a field in it that currently just holds single or
> double numbers - these numbers are basically a reference to a category
> in which the particular record should be displayed. However I have now
> been asked if I can make it so that a particular record can be displayed
> in more than one category.
> 
> All I need to do is somehow ask the field to add a forward slash to the
> front and end of the data, so the data will go from this:
> 
> 1
> 33
> 21
> 9
> 11
> 
> to this:
> 
> /1/
> /33/
> /21/
> /9/
> /11/
> 
> How do I get MySQL to do this? I guess I might have to do it in two
> steps by firstly adding the slash to the front and then lastly to the
> back. But I have no idea on how to do it. My reason for doing this is so
> that I get the webpage to look for numbers that are between the slashes.
> this will enable me to have numbers like this: /1/33/9/ enabling me to
> have a record in more than one category.
> 
> Any help would be appreciated.
> 
> Thanks
> 
> Mat
> 
> --MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
> 

First, I would like to suggest you to rethink about your whole idea
because you are going wrong directions.
It' possible to do it your way but it's not correct/the best way. For
example, one day you will need to select all products for specific
category and then you have to use LIKE to find them - what's wrong.
Think about idea to create new table "in_categories" with only 2
columns: prod_id and cat_id:
prod_id| cat_id
 123 | 1
 123 | 33
 123 | 9
 45 | 33
 28 | 33

If you still want to do it your way, I'll suggest to use comma instead /
1,33,9 (even it really doesn't change a lot) and don't put / at the
front and at the end: 1/33/9
explode('/', '/1/33/9/'); will create 5 elements of the array
explode('/', '1/33/9'); will create 3 elements of the array - the number
you need.

-afan

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to