doumiang2297 2013-05-02 12:56
浏览 8

无法在图表系统中使用其注释获取消息

The following code is fetching messages (status) with its comments from MySQL database from tables CHART and COMMENTS. The problem with the code is dieing when it's returning the messages from database causing the comment field and messages not appear in an HTML page because the msg_id didn't match anything in the table COMMETS.

Can someone help me to solve this? or what is the better way i can do this?

sample code Note: First i have a form am using to create messages then the bellow code to fetch my messages to be commented and return the comments bellow the message which has been commented.

<?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>
";
     $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>";
   }
   ?>
  • 写回答

1条回答 默认 最新

  • dsfdgdsfd23212 2013-05-02 13:01
    关注

    Why would the Comment ID be the Message ID?

    I might be wrong but shouldn't the comment record have a column such as CommentMessageID?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题