473,597 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP/MySQL Forum Comment Reply System Issues...

helimeef
77 New Member
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 16552
pbmods
5,821 Recognized Expert Expert
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
helimeef
77 New Member
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 Recognized Expert Expert
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
helimeef
77 New Member
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
jgdavies
2 New Member
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
2675
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 CANNOT VOTE NOW; you may be able to vote on a version of this proposal later. See the PROCEDURE section below if you need information about how the discussion works. PLEASE POST ANY FOLLOWUPS TO THE NEWSGROUP NEWS.GROUPS.
1
2303
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 tell me if there's any favored links to MySQL tutorials? And one more question involves MySQL security issues. Any one have a favored link for the security issues involved?
5
5058
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: Example of first topic in thread values ============================================= Forum_ID=13 (topic) Forum_Parent=0 Forum_Ancestor=13
110
10532
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 case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
0
7969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8035
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5431
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3886
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.