如何只显示1条记录而不是全部 [英] How to display just 1 record instead of all

查看:69
本文介绍了如何只显示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 (


这篇关于如何只显示1条记录而不是全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆