dongmu2026 2012-09-25 11:07 采纳率: 100%
浏览 57
已采纳

如何在没有重复和单词顺序的情况下将文本存储在数据库中无关紧要?

So I want to store searches on my site in a database and I want them to be unique even though the order of words doesn't matter for me for example:

some words

and

words some

are the same for me, and I just want to update the time of the last search.

So is there a way to do this in SQL (like UNIQUE) or should I find a solution in a server side language ?

And thanks in advance.

  • 写回答

3条回答 默认 最新

  • duanchun2349 2012-09-25 11:12
    关注

    I don't know if there is a better way to do this, but the only way I can think is that in PHP you split the string by spaces and then order it alphabetically:

    $words = explode(" ", $keywords);
    sort($words);
    $sorted_keywords = implode(" ", $words);
    

    Then when you store/search from database you'll always be using the same string no matter which order the words WERE in.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度