Hello all. Good evening.
I currently have a website were you post comments, but I want there to be a way for people to make replies to those comments. I’m new to SQL and PHP, but I think the way to do this would be to make a new table for the replies and have an ID that connects to the original comments table. How would I go about doing this?
This is what my code currently looks like,
The comments SQL I recently exported:
CREATE TABLE IF NOT EXISTS `confess` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`confess` text COLLATE utf8_unicode_ci NOT NULL,
`ip` text COLLATE utf8_unicode_ci NOT NULL,
`date` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=144 ;
Replies table I recently created in PhpMyAdmin
CREATE TABLE IF NOT EXISTS `reply` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`idconfess` int(11) NOT NULL,
`ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`date` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`reply` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
The current code on the web page
<?php require_once('Connections/Confession.php'); ?>
<?php include 'site/header.php'; ?>
<p><strong>Confession </strong>posted on <strong><?php echo htmlspecialchars($row_confess['date']); ?></strong></p>
<p><?php echo nl2br( htmlspecialchars( $row_confess['confess'] ) ); ?></p>
<?php
//echo replies here
?>
<?php include 'site/footer.php'; ?>
Thanks.