spiderd Posted December 12, 2012 Share Posted December 12, 2012 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. <!-- 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/271909-php-forum-post-not-wokring/ Share on other sites More sharing options...
Pikachu2000 Posted December 12, 2012 Share Posted December 12, 2012 Don't double post. I've deleted your other thread. Quote Link to comment https://forums.phpfreaks.com/topic/271909-php-forum-post-not-wokring/#findComment-1398923 Share on other sites More sharing options...
PFMaBiSmAd Posted December 12, 2012 Share Posted December 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271909-php-forum-post-not-wokring/#findComment-1398924 Share on other sites More sharing options...
spiderd Posted December 12, 2012 Author Share Posted December 12, 2012 (edited) 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 December 12, 2012 by spiderd Quote Link to comment https://forums.phpfreaks.com/topic/271909-php-forum-post-not-wokring/#findComment-1398925 Share on other sites More sharing options...
NomadicJosh Posted December 12, 2012 Share Posted December 12, 2012 I am not that proficient in joins but hopefully this will get you started: SELECT A.title, description FROM A INNER JOIN posts ON A.threadID = posts.thread_ID; Quote Link to comment https://forums.phpfreaks.com/topic/271909-php-forum-post-not-wokring/#findComment-1399036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.