The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP passing requested post id and title in url but not showing id in the url

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #146173

    What’s the best way to achieve this? I’d like to have a forum with the post page displaying a url like The problem is I want to look up the post in the database by it’s id instead of title because I’ve read that looking up by title is slow especially if you have a lot of posts.

    So to achieve this you would have to pass the title (or a slug of it) and the id, that’s what I currently have. I have my .htaccess set up to rewrite to Now I just want to remove the id from the url, but I don’t know how… Any help please?



    @traq Thanks for the reply and…

    Depends on how your database table is indexed – if you have an index on the title -and every title is unique- then no, it’s not a problem.

    I have my database set up like this:

    post_id (just an AUTO INCREMENT), 
    post_title (not unique), 
    post_url (unique and slug of post_title and if the slug already exists add '-2, -3, ...')

    but I don’t really know what you mean by ‘an index on the title’ ? So I guess I don’t have it :) And oh ok if matching the post_url doesn’t make any noticeable difference in speed then I could do that.

    If your DB is not indexed this way, you can create an index for it. This would be the simplest solution.

    What exactly is the index that the code creates? Could you explain that a little more please?

    instead of writing, write instead.

    Isn’t that almost the same except swich the post_id and post_title around?

    (Are you using WP (or some other CMS)?)

    No I’m trying to make my own CMS, “it’s good practice” I told myself :) and I hope I can use it in a project once it’s finished..


    Sorry for the bump but it was needed :)


    You need a unique value to search by. If the title is not unique, you run the risk of retrieving the wrong article.

    Ok, so now I have it set up to look for post_url in the database, which is unique.. So to make an index for it I just press the Primary Key button next to post_url in phpMyAdmin?


    Ok, so I created the index.. Do I need to change the code or do I just leave it to look for the post_url to find the page?


    Ok thanks :)

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.