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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.