Friday 9 August 2013

Stuck with SQL repeating first row only

Stuck with SQL repeating first row only

OK, so here goes.
I'm trying to write a blogging system (learning how to anyway), and the
problem I have is that SQL is only returning the first line in the
database. It does it as many times as records I have. I can't work out
what is going wrong. Can somebody point me in the right direction please?
<?php
include "db_connect.php";
include "functions.php";
include "style/header.php";
?>
<link href="style/style.css" rel="stylesheet" type="text/css">
<div id="main">
<?php
echo 'Welcome to the forest, '.$_SESSION['username'];
$sql = mysql_query("SELECT post_id, post_user, post_title,
post_description, post_info, post_date FROM posts");
$row = mysql_fetch_array($sql);
$post_id = $row['post_id'];
$post_user = $row['post_user'];
$post_title = $row['post_title'];
$post_description = $row['post_description'];
$post_info = $row['post_info'];
$post_date = $row['post_date'];
do { ?>
<article>
<h2>
<?php
echo $post_title;
?>
</h2>
<?php
echo $post_description;
echo $post_info;
echo 'Posted by '.$post_user.' on '.$post_date;
} while ($row = mysql_fetch_array($sql));
?>
</article>
</div>

No comments:

Post a Comment