Hi, I am creating a blog system, now i got the input system working, but now its time to show the user the blog post. I have the page mock up, ready and waiting for it to show a post.
I have set the database to create a new id for every new post so each post can easily be chosen from the table.
Show i now the end will be like website/showblog.php?postid=12 but how would i make this happen.
If anyone knows any tutorials or can help me on here will be muchly appreciated
James
Displaying 1 row from the database
Moderator: General Moderators
Re: Displaying 1 row from the database
Use the $_GET superglobal to retrieve the 'postid' from the url.
Then a mysql query to retrieve the data from the database based on the 'postid'.
Be aware that there are security concerns with this method, so remember to validate any data sent to the database before sending it.
Be warned, this is a very basic example...
drayfuss
Then a mysql query to retrieve the data from the database based on the 'postid'.
Be aware that there are security concerns with this method, so remember to validate any data sent to the database before sending it.
Code: Select all
$blog_id = $_GET'['postid'];
$mysql_connection = mysql_connect('localhost', 'mysql_username', 'mysql_pwd');
$mysql_select_db('database_name', $mysql_connection);
$result = $mysql_query("SELECT table_column FROM table_name WHERE postid=".$blog_id";", $mysql_connection);
$result_array = $mysql_fetch_assoc($result);
echo($result_array['table_column']);
drayfuss
Re: Displaying 1 row from the database
Will this work when some one click on a link to the blog post?