好的,就这样吧。
我正在尝试编写一个博客系统(无论如何都要学习如何),我遇到的问题是 SQL 只返回数据库中的第一行。它做的次数和我的记录一样多。我无法弄清楚出了什么问题。有人可以指出我正确的方向吗?
<?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>