OK, so we have a page on our site that works, it's a post with the id of 121 and is accessed via the URL http://mysite.com/viewItem.php?id=121, this is all fine and dandy but it's not as pretty as we would like to be, we want people to access it via http://mysite.com/121/border-collie-for-sale-to-good-home.
Step 1: We need to use mod_rewrite in order to take a request for /121/border-collie-for-sale-to-good-home and serve up /viewItem.php?id=121.
RewriteEngine On
RewriteRule ^([0-9]+)/[a-z-]+/?$ /viewItem.php?id=$1 [L]
We should now be able to type /121/border-collie-for-sale-to-good-home into our address bar, and view the page.
Step 2: We need to update the links in our script so that they link to this newly beautified url.
<a href="/<?php echo $postid;?>/<?php echo $thetitle;?>"
Step 3: Celebrate.
There are various nuances that can trip you up along the way, but this is essentially all the steps required.