Displaying 1 row from the database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jscrinc
Forum Newbie
Posts: 5
Joined: Fri May 14, 2010 6:59 am

Displaying 1 row from the database

Post by jscrinc »

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
drayfuss
Forum Newbie
Posts: 24
Joined: Sun Apr 25, 2010 4:57 pm

Re: Displaying 1 row from the database

Post by drayfuss »

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.

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']);

Be warned, this is a very basic example...

drayfuss
jscrinc
Forum Newbie
Posts: 5
Joined: Fri May 14, 2010 6:59 am

Re: Displaying 1 row from the database

Post by jscrinc »

Will this work when some one click on a link to the blog post?
Post Reply