Jump to content

Mysql exception.


mcarlie

Recommended Posts

I'm creating a website with articles that exist within a certain database. When you click on an article there's a small section called "similar articles" which contains articles which contain that same "tags" as the currently viewed article. For example if the article that you're looking at has a tag called "cars" then the "similar articles" section will contain articles that have the specific tag.

 

The problem is that the currently viewed article is also in the "similar articles" section so what I'm looking to do is get all the articles with the same tag with the exception of the currently viewed article.

 

So something like:

SELECT * FROM articles WHERE tags = 'cars' BUT NOT WHERE Id = 'the id of the current article'

Link to comment
Share on other sites

Off-Topic - Might want to do this:

 

Not sure how you store your tags, but if you have one row per tag

SELECT * FROM articles WHERE tags in('cars', 'motors', 'trucks') AND Id != 123 group by Id

 

If  you have all tags in a text field (Not recommended):

SELECT * FROM articles WHERE tags REGEXP 'cars|motors|trucks' AND Id != 123 group by Id

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.