duanjiebian6712 2009-08-08 12:10
浏览 29
已采纳

具有匹配mysql查询的URL标题

I have SQL rows with this information: Example - Exampleish (Exampleishbosh)

not all have () in them, so would it be a good idea to strip the

- and ()

out of the url and then just do a search with the remaining words in the SQL query?

http://www.co.com/example_exampleish_exampleishbosh/

or is this a bad idea?

  • 写回答

2条回答 默认 最新

  • doulian7252 2009-08-08 12:25
    关注

    Since the question is a bit unclear to me, I'm assuming that the information string acts as a key-sort-of-thing for additional information (like a title for an article), and there is no true GET search requirement.

    If this is the case, if allowed to modify the database structure, I would use some kind of surrogate key instead (like a numeric identifier), using the title-thingy as a slug.

    In this case, your when generating links in your website, you get both the id and slug for the target, and create an url of it in the format http://example.com/[id]/[slug]/, for example http://example.com/213/omg-lol-the-cat-jumped/.

    When processing the request in your server, you are only interested in the id ("213"), and the slug ("omg-lol-the-cat-jumped") is just for the human user to give a sneak-peek of the title, and doesn't affect the search result. You provide the page that matches the id, not the slug. This way, your searching is efficient (no SQL LIKE-matching), and less error prone (SQL injections from malformatted slugs).

    As for the (possible?) question about how to convert a string into a slug, there are many approaches to that. I would simply remove all non-alphanumeric characters, and combine the alphanumeric chunks with dashes or underscores. You probably want to cut the string length to 20-ish characters.

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

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线