Jump to content

[SOLVED] Tag System


lostprophetpunk

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/166408-solved-tag-system/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/166408-solved-tag-system/#findComment-877571
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/166408-solved-tag-system/#findComment-878792
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.