Ashoar Posted April 4, 2009 Share Posted April 4, 2009 I am working on a small forum system at the moment but i have run into a small problem. A brief overview: I have an admin panel that allows you to create a board. This is then inserted into a MYSQL table called forums. Once the forum is made it is displayed on the index page of the forum. Each forum is given an ID. So if it was the first forum made it's id would be 1 etc. I have a page called board.php. This board contains the thread listings. The url for this is made up of the forum id that you clicked into. Example: /board.php?id=3 I have an individual page called post.php which allows you to make a post. My Problem: If i enter a board, let's say it's id is 2. If i make a post in that board i wan't that particular post to show only in that board. My problem is that if i make a post in any board, that post then shows up in every other board as well as the one it was posted into. So i need to find a way so that the post will show only in the board it is posted in. Here are the codes. Index.php: <?php include 'config.php'; print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<table class='maintable'>"; print "<tr class='headline'><td width=75%>Board</td><td>Posts</td><td>Last post</td></tr>"; $info="SELECT * from post_reply where parentid='0' order by lastrepliedto DESC"; $info2=mysql_query($info) or die("Could not get threads"); while($info3=mysql_fetch_array($info2)) { $info3[title]=strip_tags($info3[title]); $info3[author]=strip_tags($info3[author]); $boards = mysql_query("SELECT forum_name, forum_desc, forum_id FROM forums") or die(mysql_error()); $boards2 = mysql_num_rows($boards); for($count = 1; $count <= $boards2; $count++) { $name = mysql_fetch_array($boards); print "<tr class='mainrow'><td><A href='board.php?id=$name[forum_id]'>$name[forum_name]</a><p>$name[forum_desc</p></td> <td>$info3[numreplies]</td><td>$info3[showtime]<br>Last post by <b>$info3[lastposter]</b></td></tr>"; } print "</table>"; } ?> This is board.php <?php include "config.php"; print "<link rel='stylesheet' href='style.css' type='text/css'>"; print "<A href='post.php'>New Topic</a><br>"; print "<table class='maintable'>"; print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Author/td><td>Replies</td><td>Last reply</td></tr>"; $info="SELECT * from post_reply where parentid='0' order by lastrepliedto DESC"; $info2=mysql_query($info) or die("Could not get threads"); while($info3=mysql_fetch_array($info2)) { $info3[title]=strip_tags($info3[title]); $info3[author]=strip_tags($info3[author]); print "<tr class='mainrow'><td><A href='message.php?id=$info3[postid]'>$info3[title]</a></td><td>$info3[author</td <td>$info3[numreplies]</td><td>$info3[showtime]<br>Last post by <b>$info3[lastposter]</b></td></tr>"; } print "</table>"; ?> And this is post.php <?php include "config.php"; if(isset($_POST['submit'])) { $name=$_POST['name']; $yourpost=$_POST['yourpost']; $subject=$_POST['subject']; if(strlen($name)<1) { print "You did not type in a name."; } else if(strlen($yourpost)<1) { print "You did not type in a post."; } else if(strlen($subject)<1) { print "You did not enter a subject."; } else { $thedate=date("U"); $displaytime=date("F j, Y, g:i a"); $subject=strip_tags($subject); $name=strip_tags($name); $yourpost=strip_tags($yourpost); $insertpost="INSERT INTO post_reply(author,title,post,showtime,realtime,lastposter) values('$name','$subject','$yourpost','$displaytime','$thedate','$name')"; mysql_query($insertpost) or die("Could not insert post"); print "Message posted, go back to <A href='index.php'>Forum</a>."; } } else { print "<form action='post.php' method='post'>"; print "Your name:<br>"; print "<input type='text' name='name' size='20'><br>"; print "Subject:<br>"; print "<input type='text' name='subject' size='20'><br>"; print "Your message:<br>"; print "<textarea name='yourpost' rows='5' cols='40'></textarea><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } print "</td></tr></table>"; ?> So would someone be able to look through the coding and possibly provide a fix to this. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/ Share on other sites More sharing options...
Showcase Posted April 4, 2009 Share Posted April 4, 2009 After a quick look, it seems in post.php when you're inserting the post it is not inserting any board reference id. Therefore, it's not adding the id for what board section it is being posted in. Then, in board.php, it needs to grab the topics that contains the board's id. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801310 Share on other sites More sharing options...
Ashoar Posted April 4, 2009 Author Share Posted April 4, 2009 Yes but each time i tried to do this it would not work, instead no threads were displayed and no posts were properly made. To add to that: The forums database and post database are 2 separate databases. So the forum id is in forums but i cannot make a post insert into that as that is only for the actual board id's. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801312 Share on other sites More sharing options...
Showcase Posted April 4, 2009 Share Posted April 4, 2009 I'm not saying put the post id in the forums table, I'm saying create a new feild in the posts table and store the board id in that. When processing the post, pass the forum id along with the contents, name, subject, etc. Then, after form validation, when inserting into the posts database table, insert the board id that was passed into the new board id feild as well. Then when loading the forum in board.php, run a mysql query to select the posts where board_id = the board's id. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801318 Share on other sites More sharing options...
Ashoar Posted April 4, 2009 Author Share Posted April 4, 2009 That is something i had tried, and even with a new field within the table. Yet when doing that the threads themselves didn't display and the posts wouldn't validate. I was hoping someone could add their method here or update my codes so that i could see exactly how it is done and see where i whent wrong when i had tried. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801319 Share on other sites More sharing options...
charleshill Posted April 4, 2009 Share Posted April 4, 2009 In board.php.... change: $info="SELECT * from post_reply where parentid='0' order by lastrepliedto DESC"; to: $info="SELECT * FROM post_reply WHERE parentid='0' AND forum_id = " . (int) $_GET['id'] . " ORDER BY lastrepliedto DESC"; $_GET['id'] is in the URL used to access the script (ie... yoursite.com/board.php?id=1) Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801323 Share on other sites More sharing options...
Ashoar Posted April 4, 2009 Author Share Posted April 4, 2009 Quote In board.php.... change: $info="SELECT * from post_reply where parentid='0' order by lastrepliedto DESC"; to: $info="SELECT * FROM post_reply WHERE parentid='0' AND forum_id = " . (int) $_GET['id'] . " ORDER BY lastrepliedto DESC"; $_GET['id'] is in the URL used to access the script (ie... yoursite.com/board.php?id=1) That gives an error fetching from the database. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801325 Share on other sites More sharing options...
charleshill Posted April 4, 2009 Share Posted April 4, 2009 Ok I just looked at your post.php.... You have to store the forum_id (board_id) of threads when you post them. Otherwise it's impossible to determine where they belong. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801329 Share on other sites More sharing options...
Ashoar Posted April 4, 2009 Author Share Posted April 4, 2009 Which is my main problem I was hoping someone could show the better way of doing this. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801341 Share on other sites More sharing options...
Ashoar Posted April 5, 2009 Author Share Posted April 5, 2009 Just knocking this back to the first back. Still in need of help. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801535 Share on other sites More sharing options...
Ashoar Posted April 5, 2009 Author Share Posted April 5, 2009 Back to first page again. Could someone show me a good way of doing this? Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801636 Share on other sites More sharing options...
Ashoar Posted April 5, 2009 Author Share Posted April 5, 2009 Back to first page again. Anyone Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-801722 Share on other sites More sharing options...
Ashoar Posted April 6, 2009 Author Share Posted April 6, 2009 I am still looking for assistance in this problem. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/152570-post-in-certain-board/#findComment-802089 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.