如何只显示1条记录而不是全部
问题描述:
嗨。
我正在尝试创建一个讨论区,您可以点击帖子的标题(从许多列表中)到仅显示用户单击的帖子的页面。然后,我想在下面添加评论。
但是,我无法弄清楚如何在数据库中只显示1条记录而不是所有记录。 (我认为这是因为数组)。
这是我的代码。它显示数据库表中的所有记录,而不是仅显示1.
Hi.
I am trying to create a discussion board where you can click on the title of a post (from a list of many) to be taken to a page where only the post the user clicked on is displayed. I then want to put comments underneath.
However, I cant figure out how to display just 1 record instead of all of them in the database. (I think that is because of the array).
This is the code I have. it displays all the records in the database table instead of just showing 1.
<?php
//connect to database
require_once ('dbconnect.php');
$displayPosts = "select postID, postDate, postName, postTitle, postBody from pmf_discussion
order by PostDate";
$rsAllPosts = mysql_query($displayPosts);
echo "<table id=\"posts\" border=\"1\">\n";
while ($Post = mysql_fetch_array($rsAllPosts)){
$postID = $Post['postID'];
$postDate = $Post['postDate'];
$postName = $Post['postName'];
$postTitle = $Post['postTitle'];
$postBody = $Post['postBody'];
echo "<tr>
<td>$postName</td>
<td>$postBody</td>
</tr>";
}
echo "</table>\n";
?>
答
displayPosts = 选择postID,postDate,postName,postTitle,postBody from pmf_discussion
order by PostDate ;
displayPosts = "select postID, postDate, postName, postTitle, postBody from pmf_discussion order by PostDate";
rsAllPosts = mysql_query(
rsAllPosts = mysql_query(
displayPosts);
echo < table id = \\ \\posts \border = \1 \> \ n;
while (
displayPosts); echo "<table id=\"posts\" border=\"1\">\n"; while (