HakonHoy
02-22-2006, 06:34 PM
I have a db called .. db5
It have a table called 'news'.. there I have 'ID (auto id)', 'Headline', 'Teaser', 'Article' and 'Author' .
When I show the Headline, Teaser, Article and Author for a record, like a "news article".. I want to be able to show links to other "news articles" in my database, that is related to the "news article" I show.. Like for example 5 related news articles.. How do I do that? Is there are sql statement or something so that it searches for related news articles and show them? Please anybody.. heeeelp :)
getweb
02-23-2006, 12:07 AM
I think the way I would do it is to assign keywords to each article, and store them in a seperate column/field. It will be difficult to come up with good matches if the database tries to simply compare every article to the rest to find relevant material... not to mention server-intensive if there are many articles.
At the very least, you could do this one-way... where each article has a set of keywords, like "formatting xbox, xbox tricks" and then it looks for those keywords in the full text of the other articles. That is going to give you pretty good relevance based on the quality of keywords you choose for each article. Remember, these are internal keywords, so forget search engines, just choose a consistent style... words that YOU are using in other relevant articles! :)
You'll probably need to do full-text searching and ask the database to return the top 5 matches sorted by relevance. This is going to be different based on which database you have... if you're using MySQL they have a page on using it:
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
It might look a little intensive but should work well for you.
BTW, an alternative would be a table with only article ID's if you selected relevant articles yourself by hand and assigned them:
ArticleID, Rank, RelatedID
1,5,12
1,4,13
1,3,14
1,2,16
1,1,44
2,5,14
2,4,65
(...)
You can then do a join on that table back to the Article table, sorted by "Rank" which will give you the pre-selected top 5 Related articles for each primary Article. It will take some SQL experience to make that work - what a great opportuntity to learn SQL!! :)
Burhan
02-23-2006, 03:33 PM
If you haven't defined a relationship or a category for an article (like, what type of article it is) you cannot use SQL to have the database create the links for you :)
You have two possible options:
1. Create categories of articles, then query all articles in the same category as the one that you have selected
2. Create a relevance/weight table (as suggested by getweb)