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 ?

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.