I need to display all the comments from the comments database table
where the $msg_id_fk = $msg_id from the messages table and I need it in a while loop
$comment_results = mysql_query("SELECT * FROM comments WHERE msg_id_fk='$msg_id' ORDER BY com_id ASC");
while ($row = mysql_fetch_array($comment_results)){
$msg_id_fk=$row['msg_id_fk'];
$comment=$row['comment'];
}
$message_results = mysql_query("SELECT * FROM messages WHERE user_on='$user' ORDER BY msg_id DESC");
while ($row = mysql_fetch_array($message_results)){
$msg_id=$row['msg_id'];
$msg=$row['message'];
$messages .='message ' . $message . ' <br />
comment ' .$comments. '';
}
Example:
___________________________________________________Message 1
Message $msg_id = 234
Comment $msg_id_fk = 234 $com_id = 1
Comment $msg_id_fk = 234 $com_id = 2
Comment $msg_id_fk = 234 $com_id = 3
Comment $msg_id_fk = 234 $com_id = 4
Comment $msg_id_fk = 234 $com_id = 5
Comment $msg_id_fk = 234 $com_id = 6
___________________________________________________Message 2
Message $msg_id = 235
Comment $msg_id_fk = 235 $com_id = 7
Comment $msg_id_fk = 235 $com_id = 8
Comment $msg_id_fk = 235 $com_id = 9
Comment $msg_id_fk = 235 $com_id = 10
Comment $msg_id_fk = 235 $com_id = 11
Comment $msg_id_fk = 235 $com_id = 12
___________________________________________________Message 3
Message $msg_id = 236
Comment $msg_id_fk = 236 $com_id = 13
Comment $msg_id_fk = 236 $com_id = 14
Comment $msg_id_fk = 236 $com_id = 15
Comment $msg_id_fk = 236 $com_id = 16
Comment $msg_id_fk = 236 $com_id = 17
Comment $msg_id_fk = 236 $com_id = 18