doyrte8419 2010-10-18 20:35
浏览 50
已采纳

使用mysql查找相关项目?

im trying to figure out how to find related topics items using mysql & php, this is my table for topics

topics{id, topic, founder,vote_up, vote_down date}

for instance say i was on topic page of php

topic {3,php,getaway, 6, 8, 20.06.2009 ect]

how would i find all the related topics to this topic

  • 写回答

4条回答 默认 最新

  • doudeng2016 2010-10-18 21:39
    关注

    I don't know why I can't comment on other people's answers so forgive this "answer"

    "i forgot to add that each topic, has a little bio about them, like 200 character about paragraph saying what the topic is about, would that be good way to relate stuff to each other?"

    This is a very unreliable way to relate anything. If this is the case, pretty much everything would relate as common words appear all over every topic. Words like "the" or "and" would relate everything in something like a full text search, depending on how you orchestrate your comparison.

    In your case, you might want to clarify HOW you plan on comparing. You already mention you are using php and mysql, so we all assume you are writing a query to find the relations. Why then are you avoiding a relational table? A keyword table? It's basic web development at this point and seems very strange that you'd be interested in a complicated work around for a very simple concept.

    blog{id, title body, date} topic{id, title} blog_topic{id, blog_id, topic_id}

    $sql = "SELECT b.*, t.* FROM `blogs` b LEFT JOIN `blog_topic` r ON r.`blog_id` = b.`id` LEFT JOIN `topic` t ON t.`id` = r.`topic_id` WHERE t.`id` = ".$whatever_topic_id_you_pass;
    

    Seems simple enough to me. Much more reliable than some weird full text search.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?