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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?