473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

PHP/MySQL Forum Comment Reply System Issues...

helimeef
I designed a little PHP/MySQL forum (just for fun), and I have commenting set up and top threads on the homepage and whatnot. I'm relatively new to PHP, and this is the biggest project I've done, but the only problem is that I can't think up a way to let people reply to an already-posted comment...

Anyway, I have a MySQL database called "forum", with three tables; "comment", "thread", and "user". I had the idea of creating a new field in the "comment" table called "reply-to_x " (each comment posted has a specific ID, and x being the comment that it replies to). But I have no idea how I would get PHP to know to place reply comments under the comments they reply to. Here is the code in showThread.php that looks through the database for comments:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     mysql_connect('localhost','root','fakepass') or die(mysql_error());
  3.     mysql_select_db('forum') or die(mysql_error());
  4.     $result = mysql_query('SELECT * FROM comment WHERE thread_id='.$t);
  5.     while($row = mysql_fetch_array( $result )) {
  6.         echo '<div class="comment" id="'.$row['id'].'">'."\n";
  7.         echo '<p class="handle">'.$row['name'].'</a></p>'."\n";
  8.         echo '<p>'.$row['message'].'</p>'."\n";
  9.         echo '</div>'."\n";
  10.     }
  11.     mysql_close('forum');
  12. ?>
  13.  
Where $t is the showThread.php?t=x part of the address (t being the thread ID), $row['id'] is the unique comment ID (for that thread), $row['name'] is the author of the comment, and $row['message'] is the comment itself.

Any ideas on how to make reply-tos possible?

Thanks,
Steven
Sep 20 '07 #1
5 16514
pbmods
5,821 Expert 4TB
Heya, Steven.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]

Create a `topics` table and a `posts` table. Add a topic ID to each record in `posts` so that you can group each post by topic.

When displaying a topic, simply fetch all posts that match the topic ID, ordered by date posted in descending order.
Sep 30 '07 #2
Heya, Steven.

Please use CODE tags when posting source code:

Expand|Select|Wrap|Line Numbers
  1. PHP code goes here.
  2.  
Create a `topics` table and a `posts` table. Add a topic ID to each record in `posts` so that you can group each post by topic.

When displaying a topic, simply fetch all posts that match the topic ID, ordered by date posted in descending order.
lol you answer every single thread. Sorry about the code tags, I was new to the forum. And I figured out a way to do the reply, in fact I now have a fully functional forum, and now I'm working on the 3rd build! YAY!
Dec 25 '07 #3
Markus
6,050 Expert 4TB
lol you answer every single thread. Sorry about the code tags, I was new to the forum. And I figured out a way to do the reply, in fact I now have a fully functional forum, and now I'm working on the 3rd build! YAY!
We'd love to see it :)
Dec 26 '07 #4
We'd love to see it :)
I'd love to show you it, but I don't really have any servers (except for my clients') that I could use as a sandbox right now, only localhost...
I'm also working on a blog and an online store, but those are barely started...
Dec 26 '07 #5
Hi,
I needed to answer exactly the same question when writing a php and mysql comment and reply system for my webpages.
For the first attempt I decided to restrict my design to one level of reply. Allowing replies to comments but not replies to replies. I use a 'reply_to' field just as you propose: any reply has a reply_to field which contains the unique id of the comment being answered. For any commment this field is NULL. I also used a 'page_id' field but this could be a 'thread_id' if needed. The MySQL query which places replies after the relevant comments can then be based around:
Expand|Select|Wrap|Line Numbers
  1. ... SELECT ... ORDER BY COALESCE ( IdReplyTo, IdComment) DESC';
  2.  
This returns IdReplyTo - unless that field is NULL in which case it returns IdComment. This makes sure that for, say comment 23, where IdReplyTo = NULL, the comment is returned then all its replies, IdRelplyTo =23which is what is needed.
For more info see: http://www.jgdprojects.co.uk/codingcomments.htm
Oct 5 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU...
1
by: Jim Carlock | last post by:
I have a couple questions about MySQL involving which version of MySQL to use. I'm looking for minimal memory use on a Windows XP machine. Which version would be best for this? And can anyone...
5
by: RioRanchoMan | last post by:
I have a forum table where the field Forum_ID of the first thread corresponds to itself in the field Forum_Ancestor, and 0 (zero) for the field Forum_Parent when it is the first topic in a thread:...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.