lostprophetpunk Posted July 18, 2009 Share Posted July 18, 2009 I am creating my own blog system using PHP, and I have come across a problem. I have started to implement a tagging feature into my system. I have got it so that it displays the tags, separately underneath the post in full view, as a link to a search page. The tags are stored in the database like so... tag1, tag2, tag3, tag4 etc... The search page shows the posts that have been tagged as the the name of the tagged they clicked on, such as search.php?tag=web%design. However, when I test this out with the below search statement, it returns nothing. $sql4 = "SELECT * FROM `posts` WHERE `tags`='$tagname'"; $res4 = mysql_query($sql4)or die(mysql_error()); Is it possible to search within the 'tags' field in the database, and display the results depending on what tag they have clicked on, such as they click on 'web design' and they get all posts that have the 'web design' tag. If anyone could help out, that would be awesome. Thanks in advance. P.S. I didn't know if this should go in the PHP or MySQL section, but this forum seemed the most appropriate one. Quote Link to comment https://forums.phpfreaks.com/topic/166408-solved-tag-system/ Share on other sites More sharing options...
GingerRobot Posted July 18, 2009 Share Posted July 18, 2009 How are you actually storing the tags? You first said you have something like "tag1,tag2,tag3,tag4", but you then have a field called "tags" in you query. Am i right in thinking that the tags field is a comma delimited string of the various tags a post has? If so, a quick and dirty 'solution' to your problem is to use the LIKE keyword: SELECT * FROM `posts` WHERE `tags` LIKE '%$tagname%'" This will return all rows where the tagname appears anywhere in the string of tags. However, a much better approach would be to use a separate table for your tags. You might like to read the following tutorial which would serve as an introduction to using multiple tables: http://www.phpfreaks.com/tutorial/data-joins-unions Quote Link to comment https://forums.phpfreaks.com/topic/166408-solved-tag-system/#findComment-877571 Share on other sites More sharing options...
lostprophetpunk Posted July 20, 2009 Author Share Posted July 20, 2009 I manage to solve this by doing some further research into MySQL queries. All I had to do was to make sure my tables in the database were a certain datatype, and then change two fields in the table so that they could do fulltext. Thanks for the help anyway. Quote Link to comment https://forums.phpfreaks.com/topic/166408-solved-tag-system/#findComment-878792 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.