Jump to content

Need an idea


tsuby

Recommended Posts

Hey guys! I have a little problem with link rewriting.
For example, when I go to the page /articles/that-article-is-nice, I got the server to use /view.php?article_name=that-article-is-nice. My question is, how can I use that slug name(which was transformed previously) to get the wanted article from the database? 

Because in the database I would have something like 'That article is... nice.?', whereas my article_name variable is different: 'that-article-is-nice'.

Can you give me any ideas on how I should approach this? My worst problem is SQL, I'm really not familiarised with it.

Link to comment
https://forums.phpfreaks.com/topic/279657-need-an-idea/
Share on other sites

put the article id number within the rewrite as well.

 

In other words,

RewriteRule /articles/(.*)_article_name /view.php?article_id=$1 [L]

The rule of thumb is that unless you are searching for rows that are similar and alike, never search using a string.  The purpose of indices is to keep an index.  If you know the index number there is not point in searching by the name of the article.  It would be like searching through a literal library for a book by its name and not its ISBN.

Link to comment
https://forums.phpfreaks.com/topic/279657-need-an-idea/#findComment-1438376
Share on other sites

Thank you for your answer, I appreciate it. That is what I had in mind, also, but it didn't really seem elegant to me. 

Now that I look more closely on some websites that I wanted to take an example from, they really use this; and so I will not have any problem implementing it in my website.

Again, thanks a lot for your answer!

Link to comment
https://forums.phpfreaks.com/topic/279657-need-an-idea/#findComment-1438402
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.