I am making question and answer system for a website. I am having an issue here. I want to make users add specific comments for each post. the script I made is similar to Quora.com so you can understand how my script is working... this is how my comment table looks like please take a look at the pic. how can I add specific comments for each post ?
//code for insert comments to the tables
function setComments($connection) {
if (isset($_POST['commentSubmit'])) {
$uid = $_POST['uid'];
$date = $_POST['date'];
$message = $_POST['message'];
//sql connection
$sql = "INSERT INTO comments (uid,date,message) VALUES ('$uid','$date','$message')";
$result = $connection ->query($sql);
}
}
//function for get comments from the databse
function getComments($connection) {
$sql = "SELECT * FROM comments";
$result = $connection ->query($sql);
while($row = $result->fetch_assoc()) {
//showing records
echo '<div id="comment_box">';
echo $row['uid'].'<br>';
//echo $row['cid'].'<br>';
echo nl2br($row['message']).'<br>';
echo $row['date'];
echo '</div>';
echo '<hr>';
}
}
I have made two functions here setComments is for insert comment
other function is for getComments
UPDATED
this question table is for ask question so users can ask the questions .