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. How can I store more data for each user? Specifically their 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? Or do I add a posts field inside the members table?
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?
In that case you need to add another table in your MySQL Database you use.
In my experience most people store the starting thread and the reply posts in 2 different tables. I wouldn’t store them in the members table, something new like ‘posts’ and ‘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’.
Thats the basics, so yea. hope this is the answer you where looking for.