简体   繁体   English

为特定用户存储帖子和数据,然后检索数据

[英]Storing posts & data for specific users then retrieving the data

I just got into somewhat complex databases (complex for me) and I have been wondering if I'm going to be doing this right. 我只是进入了一些复杂的数据库(对我而言是复杂的),我一直在想是否要正确地做到这一点。 Below is what I'm trying to achieve. 以下是我要实现的目标。

Goal: Store post data for a registered user. 目标:为注册用户存储帖子数据。 Then retrieve the posted data for that user. 然后检索该用户的已发布数据。

I have a table with registered users called members and it contains their userid , username , timeReg , password . 我有一个带有注册用户的表,该表称为members ,其中包含他们的useridusernametimeRegpassword How can I store more data for each user? 如何为每个用户存储更多数据? Specifically their posts . 具体来说就是他们的posts

If the user logs in how can I display their posts and not posts from someone else? 如果用户登录,我如何显示他们的帖子而不显示其他人的帖子? Do I create a new table called posts to store the data? 是否创建一个名为posts的新表来存储数据? Or do I add a posts field inside the members table? 还是在members表内添加一个posts字段?

So far my code for no user at all but for retrieving everything is below: 到目前为止,我的代码除了检索所有内容外,完全没有用户:

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

You are basically asking us how to get you started in making a forum or storing the posts of a forums form with a post method? 您基本上是在问我们如何开始创建论坛或使用post方法存储论坛表单的帖子?

In that case you need to add another table in your MySQL Database you use. 在这种情况下,您需要在使用的MySQL数据库中添加另一个表。 In my experience most people store the starting thread and the reply posts in 2 different tables. 以我的经验,大多数人将启动线程和回复帖子存储在2个不同的表中。 I wouldn't store them in the members table, something new like 'posts' and 'threads'. 我不会将它们存储在members表中,例如“ posts”和“ threads”之类的新东西。 As for how many rows and the names for them it is all up to you, but usual sites do 'postid', 'posttitle', 'createdtime', 'author', 'lastedittime', 'lasteditauthor', 'content', 'forumid'. 至于多少行和它们的名称完全取决于您,但是通常的站点会执行“ postid”,“ posttitle”,“ createdtime”,“ author”,“ lastedittime”,“ lasteditauthor”,“ content”,“论坛ID'。

Thats the basics, so yea. 这就是基础知识,是的。 hope this is the answer you where looking for. 希望这是您在哪里寻找的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM