Any way to find related items by tags? [PHP]/[MySQL]

Discussion in 'Programming' started by scottlpool2003, Sep 11, 2012.

  1. #1
    In the db I have rows listed like so:

    id | title | text | userid | upload_date | tag1 | tag2 | tag3 | tag4 | tag5

    I thought about writing an extra long query with: WHERE tag1 LIKE '%$tag1%' OR tag1 LIKE '%tag2%' all the way up until OR tag5 LIKE '%$tag5%'

    Is there any easier way to do it?
     
    scottlpool2003, Sep 11, 2012 IP
  2. Web Solutions

    Web Solutions Peon

    Messages:
    64
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    0
    #2
    Two options:
    • make it so that there would be only one tag field (values separated by comma or anything else of that kind);
    • generate SQL query dynamically (Google has quite a few good examples on this).
     
    Web Solutions, Sep 11, 2012 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    Thanks

    So simple yet so effective. I have an awful habit of making way too much work for myself!
     
    scottlpool2003, Sep 12, 2012 IP