bobdole1989 Posted October 8, 2011 Share Posted October 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248673-simple-message-board-reply-feature/ Share on other sites More sharing options...
mikesta707 Posted October 8, 2011 Share Posted October 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/248673-simple-message-board-reply-feature/#findComment-1277145 Share on other sites More sharing options...
bobdole1989 Posted October 8, 2011 Author Share Posted October 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/248673-simple-message-board-reply-feature/#findComment-1277149 Share on other sites More sharing options...
trq Posted October 8, 2011 Share Posted October 8, 2011 You can place the id of the current thread in the form that will be used to post a new reply as a hidden field. Quote Link to comment https://forums.phpfreaks.com/topic/248673-simple-message-board-reply-feature/#findComment-1277152 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.