Reputation: 582
I've been writing a small blogging system to advance my knowledge of PHP, and I'm having fun writing it. I've been using one page, coupled with jquery's pajinate plugin to display all my blog entries through one page. However, my question here is can I generate a page which displays a blog article with the id of 2?
What I want to do is generate the article, but dump it to a page (content/article-name-here.php). Is there any way of automating the process?
(Sorry if it's not clear)
Upvotes: 1
Views: 255
Reputation: 12955
Here's a basic SQL query:
SELECT * FROM blogEntries WHERE id=2
(Note: Never use SELECT * unless you're actually using all the data)
I have done the same project as you, creating a simple blogging engine, and I use the same page for both the general list and the single article.
Using a URL such as example.com/?blogId=2
you can modify your query:
$SQL = 'SELECT * FROM blogEntries';
//if $_GET['id'] has a value, append it to query
if(isset($_GET['id'])){
$SQL .= 'WHERE id=' . $_GET['blogId'];
};
//Execute SQL Query
//process your data as you want it to appear
If you want custom URLs for each blog entry, you will want to look in to Mod_Rewrite: http://www.workingwith.me.uk/articles/scripting/mod_rewrite
Upvotes: 2