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
https://forums.phpfreaks.com/topic/258064-mysql-exception/
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
https://forums.phpfreaks.com/topic/258064-mysql-exception/#findComment-1323188
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.