2011-03-08 28 views
0

我刚刚进入了一些复杂的数据库(对我来说很复杂),我一直在想我是否会这样做。以下是我想要实现的。为特定用户存储帖子和数据,然后检索数据

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

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

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

到目前为止,我在完全没有用户,但用于检索的一切代码如下:

$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*"; 
} 

回答

0

你基本上是问我们如何让你在做一个论坛或存储论坛的帖子开始形成后期的方法?

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

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

+0

我会使用join方法将字段连接在一起吗?谢谢回复。 – Kyle 2011-03-08 10:05:42