Php can';t在图表系统中使用逗号获取消息
下面的代码从MySQL数据库的图表和注释表中获取带有注释的消息(状态)。当代码从数据库返回消息时,问题就消失了,这导致注释字段和消息不会出现在HTML页面中,因为msg_id与COMMETS表中的任何内容都不匹配 有人能帮我解决这个问题吗?或者我可以用什么更好的方法来做 示例代码 注意:首先,我有一个用于创建消息的表单,然后使用下面的代码获取要注释的消息,并在已注释的消息下面返回注释。Php can';t在图表系统中使用逗号获取消息,php,mysql,Php,Mysql,下面的代码从MySQL数据库的图表和注释表中获取带有注释的消息(状态)。当代码从数据库返回消息时,问题就消失了,这导致注释字段和消息不会出现在HTML页面中,因为msg_id与COMMETS表中的任何内容都不匹配 有人能帮我解决这个问题吗?或者我可以用什么更好的方法来做 示例代码 注意:首先,我有一个用于创建消息的表单,然后使用下面的代码获取要注释的消息,并在已注释的消息下面返回注释。 <?php //MYQSL query to select from two tables chart
<?php
//MYQSL query to select from two tables chart and comments
//this query is not returning anything because the script is dieing ON ch.msg_id=co.comment_id, it cant find co.comment_id because has not yet created.
$result = mysqli_query($con, "SELECT ch.msg , ch.msg_id , co.comment , co.comment_id
FROM chart AS ch
JOIN comments AS co
ON ch.msg_id=co.comment_id
ORDER BY ch.msg_id, co.comment_id");
$last_msg = null;
while($row = mysqli_fetch_array($result))
{
if ($row['msg_id'] !== $last_msg) {
if ($last_msg !== null) {
echo "<table>";
}
echo "<table border='1' width='600px'>
<tr>
<td>
$row[msg]
</td>
</tr>\n";
$last_msg = $row['msg_id'];
}
//all comments should appear here if comment_id match msg_id in COMMENTS table
echo("
<tr>
<td>
$row[comment]
<p></p>
//HTML form which will insert the comments into table COMMENTS
//this form should appear below each message since its a comment field
<form action='drop_comment.php' method='post'>
<input type='text' name='comment' placeholder='drop a comment...' value='' class='add_hook'>
<input name='comment_id' type='hidden' value='$row[msg_id]'>
</form>
</td>
</tr>
");
echo "</table>";
}
?>
为什么注释ID是消息ID
我可能错了,但注释记录不应该有一列,如CommentMessageID吗?我的意思是,如果msg_id是2121,则注释隐藏字段将回显该id,并将其放置在comment_id行的表注释中,然后MySQL查询必须将msg_id与comment_id匹配,以显示消息下方的注释该id,如果错误,请更正我您的代码说//此查询没有返回任何内容,因为脚本位于ch.msg\u id=co.comment\u id上,它找不到co.comment\u id,因为尚未创建。评论和消息表的结构是什么?评论表包含id、msg\u id和msg,而图表表包含id、comment\u id和comment,仅此而已