dongou2019 2011-04-18 19:28
浏览 28

seo url在php中

I have read about "slugs" but I still can`t figure out how to use them. How to properly save slugs in database ?

Lets say i have url like this http:/example.com/samsung/samsung_continuum_android_smartphone /

This is what I do

select category_id from categories where category_name = 'samsung'

After that I do query like

select slugs from my_table where category_id = (lets say 3 where is samsung)

Result is something like samsung_continuum_android_smartphone samsung_some_other_phone.

After that I can do something like this

select * from info where title = 'samsung_continuum_android_smartphone'

to get the information about the product. Is this the right way to do it ?

  • 写回答

1条回答 默认 最新

  • douju2014 2011-04-18 19:42
    关注

    Your going a little over board, slugs are the exact same principle as unique identification numbers, the only difference is that a slug represents natural language for ease of reading as well as SEO.

    Now I see that your performing 2 queries to get the row that matches the slug, where as you should only select 1 row from your info where the slug matches the container.

    For instance:

    SELECT * FROM categories WHERE category_slug = 'samsung';
    

    the category_slug would be just as unique as category_id, thus removing any conflict's that may occur.

    now if you construct your table scheme so that the slugs are only uniq to the category, this would remove conflicts but each slug for a post would need to be unique for the category, you can then select the correct post from the post table filtered by the category.

    SELECT * FROM posts WHERE category_id = (SELECT category_id FROM categories WHERE category_slug = 'sumsung') AND WHERE post_slug = 'this_would_be_the_slug_for_the_post'
    

    both of these values can be pulled from $_GET and placed into the above SQL String.

    评论

报告相同问题?

悬赏问题

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