![]() |
Advice? How to Tag? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Advice? How to Tag? (/showthread.php?tid=23687) |
Advice? How to Tag? - El Forum - 10-19-2009 [eluser]georgerobbo[/eluser] I am looking to add tags to my posts. I know you should have a different table for tags and posts. However I am unsure how to link the two? My database structure is as follows. Code: -- Advice? How to Tag? - El Forum - 10-19-2009 [eluser]daparky[/eluser] In the tag table you would have something like tagid, postid and tagname. Whenever you add a tag you will need to add it to the tag table with the post id. If you use a tagname twice you will need to check to see if the tagname is in already there and use the tagid. Then you would do a tag page and do a query like select * where tagid = 1. Hope this makes sense. Advice? How to Tag? - El Forum - 10-19-2009 [eluser]jedd[/eluser] You need two tables. tag id name post_tag id tag_id // links to tag.id post_id // links to post.id Advice? How to Tag? - El Forum - 10-19-2009 [eluser]georgerobbo[/eluser] Is there a better, cleaner method for selecting the ID from the variable $data['rand'] My controller is the following. Code: <?php Advice? How to Tag? - El Forum - 10-19-2009 [eluser]jedd[/eluser] [quote author="georgerobbo" date="1255995375"]Is there a better, cleaner method for selecting the ID from the variable $data['rand'] [/quote] I don't understand the question. What is $data['rand'] and what does get_random_single() do? Advice? How to Tag? - El Forum - 10-19-2009 [eluser]georgerobbo[/eluser] Sorry. $data['rand'] selects everything from the table below (which contain the posts). Code: -- So to get the tags relevant to those posts I am querying the tag table with the ID of the post being displayed. To do so I need to set the ID of the post in my controller and I have done that using a foreach loop. I was wondering if there was a prettier way of doing it. Advice? How to Tag? - El Forum - 10-19-2009 [eluser]jedd[/eluser] Oh, okay. get_tags ($postid) would then contain some SQL like this (untested, of course, so play with this a bit) SELECT tag.name FROM post_tag WHERE post_tag.post_id = $postid LEFT JOIN tag ON tag.id = post_tag.tag_id |