Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    Romania
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Retrieve database article with slug string

    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?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Simply replace the - with spaces. Although, you can use underscores instead of hyphens if you want; those won't need to change anything since an underscore is a wildcard character in SQL, then use a LIKE to query it.
    Case isn't relevant; the default search is to be case insensitive. You need to force it to do case sensitive matching by changing the collation. So that's not an issue with the 'T' versus 't'. I don't know if it has the period in it or not, and I don't know if its designed to truncate a certain length of title or not either. So you may need to use a % at the end of your search criteria and use a LIKE.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    tsuby (06-27-2013)

  • #3
    New Coder
    Join Date
    Jul 2011
    Location
    Romania
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks a bunch!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •