Jump to content
Larry Ullman's Book Forums

How Do You Create Permalinks To Mysql Blog Content


Recommended Posts

Hi,

 

I have studied php6 and Mysql 5 for dynamic websites + other books and courses, but I need help creating permalinks to my blog posts.

 

I have a Website with blog content in a Mysql database, flemingwebmedia.com, and my aim is to add social buttons to blog posts that include a permalink to the post they are attached to.

 

I can't figure out where to start to accomplish this?

 

Can anybody help me please?

 

Thanks,

 

Brent

Link to comment
Share on other sites

If you are storing the individual blog entries within a DB, then I'm guessing that each entry has some sort of ID associated with it, right?

If that's the case, then you can always used that unique ID to reference the content, and it will never change.

 

For example, if you have a script called view_blog_post.php that displays the various blog entries, then by adding some sort of parameter onto the end of the URL, you should be able to get what you want.

 

Let's imagine that your DB is set up as follows:

 

Table name: blog_entries

id blog_entry

1 "PHP rocks! You know..."

2 "It's amazing how..."

 

Then you could use the following link to permanently link to the first blog entry about "PHP rocks!" as follows:

http://www.domain-name.com/path/to/script/view_blog_post.php?id=1

 

That part after the question mark in the URL is what would mark your individual blog entries. For the second blog entry in the DB, you'd use id=2 instead. From there, a simple PHP GET request and a MySQL query later, and you'd have the corresponding content.

 

Does that help?

  • Upvote 1
Link to comment
Share on other sites

Thanks very much for your reply.

This does make perfect sense to me, and I have a page that already operates like that (it displays the post based on an id).

 

What I was hoping to achieve was a solution that would include the title of the blog post in the permalink without the post_id, like:

http://www.domain-name.com/path/to/script/post-title

 

I have seen other sites using permalinks that look more like this & from what i have read they are easier to pass as external links for the purposes of sending the permalink in a tweet for example. The problem I see in creating a permalink like this is that it has to be re-interpreted again on my site and I'm not sure about how to manage that process.

 

However - I have just been testing out your suggestion and it turns out that I can successfully link directly to a specific post on my site from an external location using that method. So I might not need to worry about the added complexity of creating a link with no id in it. Also, using bitly.com to shorten my original url still works in linking back to my post so maybe I could send the shortened version of the url & it would be tidier to send.

 

Thanks for your help.

 

Brent

Link to comment
Share on other sites

Yes, I know exactly what you mean by the "pretty URLs" (as they call them).

Actually, achieving that is only a step beyond what you already have.

You have to use something called mod_rewrite on Apache servers to achieve that, and it requires some knowledge of regexes too, which can be a bit hairy.

 

For the raw info, check out this link on the Apache home page:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

 

For a better explanation, check out either Larry's E-Commerce book or his PHP Advanced book; both talk about mod_rewrite.

 

Hope that helps.

  • Upvote 1
Link to comment
Share on other sites

Thanks again,

 

I will look at the info you suggest here and sorry I didn't get back to look at your second response sooner.

My links are currently working fine & I have included a tweet button on my posts that successfully sends my perma link,

this page contains an example http://www.flemingwebmedia.com/blog/blog_comments.php?blog_id=1&s=0

 

I am improving my site with time, and my original idea was to display the full length blog posts on the front page without the usual 'click to read more' that takes you to the full post. I'm thinking of reconsidering this approach because displaying the full post provides no incentive to click to go to the comments page that contains the tweet button for sharing ...

 

Designing from scratch is always a toss up with how you approach these things.

Thanks again.

 

Brent

Link to comment
Share on other sites

Agreed. When you design from scratch, you suddenly have to make a bunch of decisions that are more or less automated for you with more established approaches.

 

This might not be relevant since I'm using IE6 at work, but when I tried to view your link, I didn't get a scroll bar to scroll down the page. I'm not sure why that is, but I'm wondering if it has to do with absolute positioning. Did you by chance absolutely position everything?

 

Well, that's neither here nor there, because, as I mentioned, I'm using IE6, which is pretty much irrelevant these days.

 

Anyway, best of luck with your blog and the continued development of it.

Feel free to ask questions here any time.

Link to comment
Share on other sites

Thanks,

 

and I admit I did neglect earlier versions of IE.

I just downloaded IETester and agree the site appears to have big issues with css / php scripts etc. running on earlier versions of IE.

Not sure whether I will bother too much about it because my original intention was to only worry about the latest couple of versions of IE.

 

Possibly I'm ignoring a few people but nobody has complained to me and people that don't know about these things often turn their computers over quickly enough that they upgrade their browsers one way or another. Heres hoping.

 

Brent

Link to comment
Share on other sites

 Share

×
×
  • Create New...