存储帖子&然后,特定用户的数据将检索数据

时间:2011-03-08 09:37:14

标签: php mysql sql

我刚进入一些复杂的数据库(对我来说很复杂),我一直想知道我是否会这样做。以下是我想要实现的目标。

目标:存储注册用户的发布数据。然后检索该用户的发布数据。

我有一个名为members的注册用户表,其中包含useridusernametimeRegpassword。如何为每个用户存储更多数据?特别是他们的posts

如果用户登录我如何显示他们的帖子而不是其他人的帖子?我是否创建了一个名为posts的新表来存储数据?或者我在posts表格中添加members字段?

到目前为止,我的代码完全没有用户,只是用于检索所有内容,如下所示:

$sql_query = "SELECT * FROM members ORDER BY timeReg DESC";
$result = mysql_query($sql_query);
if (mysql_num_rows($result)) {

    echo "<table border='1' cellspacing='0' width='62%'>";
        echo "<tr>";
        echo "<th width='15%'>Time Registered</th>";
        echo "<th width='15%'>Username</th>";
        echo "<th width='15%'>Encrypted Password</th>";
        echo "<th width='15%'>IP Address</th>";
        echo "<th width='2%'>Delete User</th>";
        echo "</tr>";
    while ($row = mysql_fetch_row($result))
    {
        echo "<tr>";
        echo ("<p><td>" .genericTime($row[2]). "</td><td>$row[0]</td><td>$row[1]</td><td><i>$row[3]</i></td><td><a href=\"delete.php?time=$row[2]&user=$row[0]&pass=$row[1]\"><center>[x]</center></a></td></p>");
        echo "</tr>";
    }
    echo "</table>";
}
else
{
    echo "*No Members*";
}

1 个答案:

答案 0 :(得分:0)

您基本上问我们如何让您开始创建论坛或使用post方法存储论坛表单的帖子?

在这种情况下,您需要在您使用的MySQL数据库中添加另一个表。 根据我的经验,大多数人将起始线程和回复帖子存储在2个不同的表中。我不会将它们存储在成员表中,像'posts'和'threads'这样的新东西。 至于有多少行和它们的名称都取决于你,但通常的网站都有'postid','posttitle','createdtime','author','lastedittime','lasteditauthor','content',' forumid”。

这是基础知识,所以是的。希望这是你寻找的答案。