1

Ok. I'm using MySQL and PHP. I have a table called "Pictures" and a field in that table called "Tagged." This field is an array of UserIds which I imploded and stored as a string.

example: 114,159,14,334

Lets say I want to return all the rows in "Pictures" where a particular UserID, say 14, exists somewhere in the "Tagged" field's array. How can this be done?

2
  • You're headed down a bad path. Normalize the schema first. Add a UserPictureTag table. Commented Jan 17, 2011 at 5:56
  • do you have any links or suggestions as to a better approach? The pictures table is pretty small right now, but I can see how this approach might slow things down on a larger scale. Commented Jan 17, 2011 at 6:38

2 Answers 2

4
select * from pictures where FIND_IN_SET(14,Tagged);
2
  • this query isn't returning any results. Commented Jan 17, 2011 at 6:16
  • @rollsRLS8822:Pass the id as a first argument and column name as a second argument will work check updated one. Commented Jan 17, 2011 at 6:25
0

Start it with a , and end with a , like this: ,114,159,14,334, and then do a SELECT FROM Pictures WHERE tagged='%,14,%'

Just an idea, I really don't know... I've never done this before. Traditional blog tagging may be similar enough that you could look up some tutorials to learn from them.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.