P
P
Peter Zubkov2015-08-02 16:08:01
PHP
Peter Zubkov, 2015-08-02 16:08:01

How to make CNC without id?

There is a URL like site.ru/book?id=1. And I want to do this: site.ru/book/php-dlya-chajnikov.
The content of the page is retrieved from the database by id. I don't want to add an ID to the end of the address.
I see two possible solutions:
1. Pass id via POST
I don’t even know how to implement it, because I don’t want to register a hundred times 2. Display from the database by id like “php-dlya-chajnikov”.form method="post"

SELECT id, title, author FROM books WHERE id='php-dlya-chajnikov'

Here, in my opinion, the speed will be low. I heard that it is not recommended to use a varchar field as a primary key.
Surely there is some solution used by large sites:
mann-ivanov-ferber.ru/books/stranica_v_den
litres.ru/adam-trahtenbergdevid-sklyar/php-recepty...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
D', 2015-08-02
@peterzubkoff

It's called a bicycle.
The problem is solved very simply:
"site.ru/book/php-dlya-chajnikov" - this part of "php-dlya-chajnikov" is called "slug".
An additional slug field is created in the database, where, when creating a record, the abbreviated name of the post is automatically or manually written.
Then we just do a selection on it:

SELECT id, title, author FROM books WHERE slug='php-dlya-chajnikov'

M
Mykola, 2015-08-02
@iSensetivity

Here, in my opinion, the speed will be low.

You've had enough, don't be afraid.

B
biryerde, 2015-08-02
@biryerde

1. Pass id via POST

so it is not necessary ...
through rewriting we take the name from the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question