Jump to content

Recommended Posts

Hello,

Im doing a project which is basically making a forum using PHP,HTML and MYSQL database. I basically using a PHP script to import data into the MySQL database and another PHP script to show all the data in the MySQL table on brower. So in a nut shell im using a combination of these two script to simulate a forum.

 

Ive got the these working which are:

login

create a new thread

display all the threads

create a new post

display all the posts

 

however the problem I have is that all posts data from the MySQL table is showing in every single thread, these should happenI only want the posts to show in the threads they corresspond to, I taught it would do this automatically because did all the primary and foreign stuff with my three MySQL tables which are users,threads,posts bellow is the coding for my posts script and MySQL cmd.

 

sql.jpg

 

<!-- Link to CSS-->
<link rel="stylesheet" type="text/css" href= "CSS/default.css" title="Main">
<p>
Welcome to the posts Page!!!!!!!!!
</p>
To start a new post fill in the details and...
<form name "input" action="new_post.php" method="post"></p>
<input type="text" name="thread_ID" size="25" value="Input thread ID here"><br>
<input type="text" name="description" size="25" value="Description"><br>
<input type="text" name="date" size="25" value="Post Date"><br>
<p><input type="submit" value="Submit"></p>
</form>
<form name "input" action="threads.php" method="post"></p>
<p><input type="submit" value="Back"></p>
</form>
<p>Click the "Submit" button to create a post.</p>
<?php
$mysqli = mysqli_connect("localhost", "root","","forum");
$myquery = "select * from posts";
$result = mysqli_query($mysqli,$myquery);
echo "<table>";
while($record = mysqli_fetch_array($result,MYSQL_ASSOC))
{
$sky = $record["postID"];
$ground = $record["thread_ID"];
$water = $record["description"];
$air = $record["date"];
echo "<tr>";
echo "<td>";
echo $sky;
echo "</td>";
echo "<td>";
echo $ground;
echo "</td>";
echo "<td>";
echo $water;
echo "</td>";
echo "<td>";
echo $air;
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>

Link to comment
https://forums.phpfreaks.com/topic/271909-php-forum-post-not-wokring/
Share on other sites

it would do this automatically

 

In programming, automatic means that someone wrote code to do it.

 

You need to write your query statement so that it joins the information you want ON/USING the corresponding columns in the tables.

So what would hte query look like in this case because all I got for now is "

"select * from posts"

which just displays everything in the tables

 

also i have thread_ID in posts tables linked with threadID do I need to change the database in anyway.

Edited by spiderd
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.