I have a PHP script to save new articles into MySQL with the following parameters:
ID, Date, Category, Title, Content, Slug
Where the Slug is the same title but with - dashes like this:
this-is-a-nice-title
Then I have the articles.php where all articles are displayed and linked to read-article.php where the selected article can be read in a seo-friendly url like this
domain.com/news/this-is-a-nice-title
Just like anyone else does, the page read-article.php sends a query to MySQL like this:
SELECT * FROM articles WHERE slug=?
until that everything is fine, every tutorial on Internet tells you to do that and it works.
But here is the problem: If some articles have the same title by any reason, any error or misstake, that would be a problem. So it is best to query using the ID instead like this:
SELECT * FROM articles WHERE id=?
The thing is that I cannot make it to work, I just get error 404 all the time because when there are no results I set it to go to error-404.php while testing/developing
No tutorial teach you how to create friendly urls without querying MySQL by the slug name. Thus my question is: Is it possible to do it another way, tother than to query the slug in MySQL?