- This topic is empty.
August 8, 2013 at 11:52 am #146173
What’s the best way to achieve this? I’d like to have a forum with the post page displaying a url like
example.com/forums/category/post-title. 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
example.com/forums/post.php?id=post-id. Now I just want to remove the id from the url, but I don’t know how… Any help please?
Thanks.August 8, 2013 at 2:20 pm #146181
@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 example.com/forums/category/post-id/post-title, write example.com/forums/category/post-title?id=post-id instead.
Isn’t that almost the same except swich the
(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..August 11, 2013 at 9:29 am #146394
Sorry for the bump but it was needed :)August 11, 2013 at 12:12 pm #146405
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_urlin the database, which is unique.. So to make an index for it I just press the Primary Key button next to
post_urlin phpMyAdmin?August 11, 2013 at 1:51 pm #146423
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?August 20, 2013 at 2:20 pm #147631
Ok thanks :)
- The forum ‘Back End’ is closed to new topics and replies.