locked
Implementing Tags RRS feed

  • Question

  • User2129316869 posted

    Please how do I implement tags in my project just a used in posting articles in this forum. Thanks.

    Monday, June 9, 2014 11:31 AM

Answers

  • User281315223 posted

    I suppose that you could add a field within your database that contained all of the tag(s) that were associated to a specific thread or discussion. Whenever a user either updated or posted a reply, you would read the tags that were present and either have a seperate table to explicitly indicate which flags were on which topics or place the tags on the actual "discussion" in your database. As with most things, there are likely countless ways to implement this.

    If you are referring to how to actually use a mechanism similar to the one in this thread, you might try using some jQuery-based "tagging" element similar to one of the ones listed below :

    Or you could check out this extremely extensive Stack Overflow discussion that covers a wide range of ways to implement this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 9, 2014 12:43 PM
  • User-1416423428 posted

    A couple of ways to approach this problem, each with its own cons and pros. 

    Simplest

    The simplest is just having a single tag field in your database record, you enter your tags separated by commas and save to this field i.e. "tag1, tag2, tag3, ...." without the quote. 

    Problem is when it's time to search/display all records with "tag2" in them, then you'd have to use LIKE '%tag2%' in your query and SQL will do a brute force search on all your records. It works, but could get slow if your database is huge.... but in my experience doing a LIKE '%keyword%' search on 60K+ records is still fast, so it's viable for some kind of sites. 

    Another option 

    Another option is accept tags from users separated by commas, then process it behind the scenes. Split the tags using (,) commas as the separator, then save each tag, along with the parent record to the database in a separate table.  If you need to find all records with 'tag2' in them, it's a simple SQL query and very fast.  

    This gets hairy in your admin program when you want to update the parent record. You'd have to retrieve all it's tags (using SQL), combine them and show the commas, populate the form field, and display back to the user. User edits the tag (add new tags, or delete tags) and then you update the tables again.  -- for me I found it's easier to delete all tags that belong to the parent record ID, then just re-add all the updated tags again as described in previous paragraph above.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 9, 2014 1:29 PM

All replies

  • User281315223 posted

    I suppose that you could add a field within your database that contained all of the tag(s) that were associated to a specific thread or discussion. Whenever a user either updated or posted a reply, you would read the tags that were present and either have a seperate table to explicitly indicate which flags were on which topics or place the tags on the actual "discussion" in your database. As with most things, there are likely countless ways to implement this.

    If you are referring to how to actually use a mechanism similar to the one in this thread, you might try using some jQuery-based "tagging" element similar to one of the ones listed below :

    Or you could check out this extremely extensive Stack Overflow discussion that covers a wide range of ways to implement this.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 9, 2014 12:43 PM
  • User-1416423428 posted

    A couple of ways to approach this problem, each with its own cons and pros. 

    Simplest

    The simplest is just having a single tag field in your database record, you enter your tags separated by commas and save to this field i.e. "tag1, tag2, tag3, ...." without the quote. 

    Problem is when it's time to search/display all records with "tag2" in them, then you'd have to use LIKE '%tag2%' in your query and SQL will do a brute force search on all your records. It works, but could get slow if your database is huge.... but in my experience doing a LIKE '%keyword%' search on 60K+ records is still fast, so it's viable for some kind of sites. 

    Another option 

    Another option is accept tags from users separated by commas, then process it behind the scenes. Split the tags using (,) commas as the separator, then save each tag, along with the parent record to the database in a separate table.  If you need to find all records with 'tag2' in them, it's a simple SQL query and very fast.  

    This gets hairy in your admin program when you want to update the parent record. You'd have to retrieve all it's tags (using SQL), combine them and show the commas, populate the form field, and display back to the user. User edits the tag (add new tags, or delete tags) and then you update the tables again.  -- for me I found it's easier to delete all tags that belong to the parent record ID, then just re-add all the updated tags again as described in previous paragraph above.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 9, 2014 1:29 PM
  • User-453926175 posted

    You can download the Photo Gallery Template. It has a tagging example within it for tagging the photos with keywords.

    ~J Bishop

    Wednesday, June 11, 2014 2:35 PM