I created a blog with fields are blog_title and blog_contents these data are stored into mysql database and i want to display this blog post on www.example.com/blog page with specific url blog_title
eg: www.example.com/blog/blog title
Then particular title of the blog should be fetch form database and displayed over the page.
How can we achieve this?
Some quick guidelines how I would do it:
Start from the url www.example.com/blog.php?id=1
You get the id from the url:
$blogId = $_GET['id']
Then your SQL query:
SELECT * FROM blogs where id = $blogId
Build your page with the result of this query.
To get the url showed like you want: URL Rewriting
You have o search for two things:
mod_rewrite / url rewriting, because on your server won't be a folder called /blog/this-is-my-blog-title (mod_rewrite will redirect that url to your eg index.php which does the rest)
you need that index.php which does the rest for you -> converting an url-blog-title into your real blog title in your database to fetch its content. The most easiest way is by using urlencode()
, but then it will look really ugly. You need some script / code which converts whitespaces into hyphen (-) There are also some tutorials out there, just search for "seo friendly blog urls" for example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.