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条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c