Jump to content

Post in certain board


Ashoar

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.