Jump to content

Simple Message Board Reply Feature


bobdole1989

Recommended Posts

Hi all, I'm very new to the wonderful world of php, so I'd appreciate any and all help in the matter. I've greatly simplified the code below to hopefully help you in helping me. Thanks!

 

Ok, so I'm integrating a very simple message board feature into my site. The basic idea is that people post a comment, and have the option of replying to existing comments. I'm definitely not looking for a complete forum; just something that allows users to post and reply.

 

I've tackled the posting bit easily enough. I have a form. Users fill in the form and the message, along with user information, is sent to a MySQL database. The information includes the username(Poster), the message(Message), an id that corresponds to the topic in question(Messid), a unique ID code for the message itself (ID), and a number of other variables like date and rank.

 

I then use a while statement to bring up all of the messages that pertain to a particular topic; The output will only show messages that share the same Messid, and they are arranged in terms of descending ID:

<? 
while($row = mysql_fetch_array($resultcomments))
  {
    $poster=$row['Poster']; 
  $message= $row['Message'];
$ID=$row['ID'];

echo $message.$poster.$ID;

}

 

 

So far, so good. What I want is for users to be able to click on any one of the particular messages, and post a response comment that will appear directly below the message to which it responds. Any ideas how I might go about such a task?

 

So far, I've created a new MySQL table that corresponds to these "subcomments". Each subcomment has a "subID" that corresponds to the ID of the message to which it responds. By including a while statement within the while statement above, I can successfully list all of the subcomments that correspond to a message directly below it. The problem, of course, is that I have to insert the subID values manually in php_my_admin. I'm hoping there's a way for php to automatically detect the ID value of the message in question...

 

Many many thanks for any assistance I can get. Once this revolution in communication makes me a billionaire, I will be certain to reward you most properly. Thanks again.

 

 

Link to comment
Share on other sites

When you create the messages (IE do the actual inserting of the submessages into the database) you will also need to store the message being replied to's ID into the subID column. Now there are various ways to do this, depending on how your message system is set up. What I have done in the past is have a page (called view.php or something) that shows each individual thread. This page would get the current message to be viewed's ID from $_GET (which of course could be passed through a link on the previous page). In the form that allows people to add sub-comments, I simply pass the comments ID (gotten via $_GET) in a hidden field, and in the form processing I store the value of the hidden field. IN your case, you would want to store this value in subID.

Link to comment
Share on other sites

Thanks for the reply. I've thought about doing something akin to what I think you're suggesting. Essentially each message, if clicked, directs to a url with the ID in the address. When submitting the form, the id in the url is submitted into the SubID field. It works fine, but it requires redirecting in the first place. I was hoping to find a method that could allow for the creation of messages AND submessages all on the same page. Even if it means delving into things like Javascript, which I am not at all familiar with.

 

If I'm not making any sense, or if I've missed something, please feel free to let me know. I appreciate the current info very much. Thanks

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.