Php 模态显示变量的所有记录,而它应该显示一条记录?

Php 模态显示变量的所有记录,而它应该显示一条记录?,php,mysql,codeigniter,Php,Mysql,Codeigniter,我在模式中调用var MessageBodyFull,只想看到特定记录的消息体,但所有记录都会显示出来。我试着将模式移动到堆栈中的不同位置,围绕着php for循环工作,但似乎没有任何效果 添加上下文:“限制10”将数据表限制为10条记录,显示消息正文的前65个字符。每个记录都有一个指向模式的链接,我想在其中显示完整的消息体,但当前单击该链接时,模式包含所有10条记录的完整消息体 查看(相关片段) 控制器(相关片段) 我假定堆栈/队列的结构存在问题 修复:将所需变量(var MessageBod

我在模式中调用var MessageBodyFull,只想看到特定记录的消息体,但所有记录都会显示出来。我试着将模式移动到堆栈中的不同位置,围绕着php for循环工作,但似乎没有任何效果

添加上下文:“限制10”将数据表限制为10条记录,显示消息正文的前65个字符。每个记录都有一个指向模式的链接,我想在其中显示完整的消息体,但当前单击该链接时,模式包含所有10条记录的完整消息体

查看(相关片段)

控制器(相关片段)


我假定堆栈/队列的结构存在问题

修复:将所需变量(var MessageBodyFill=MessageBodyFull)与所选记录对齐,并使用document.getElementById().innerHTML将其调用到模式中

表格

<table id="tableDataset">
 <thead>
  <tr>
     <th><i class="icon-briefcase"></i> Recipient</th>
     <th class="hidden-xs"><i class="icon-question-sign"></i> Message Body</th>
     <th><i class="icon-bookmark"></i> Date</th>
     <th><i class="icon-bell"></i> Status</th>
  </tr>
</thead>
<tbody>
  <?foreach($letter_feed as $feed_item): ?>
     <tr>
        <td><?=$feed_item->Recipient?></td>
       <!-- FIX --> <td class="hidden-xs"><?=$feed_item->MessageBody?> <a href="#messageBodyFull" class="open-MessageBodyFill btn btn-primary"  data-id="<?=$feed_item->MessageBodyFull?>" data-toggle="modal">Full Message</a></td>  
        <td><?=$feed_item->Created?> </td>
        <td><?=$feed_item->StatusDescription?></td>
     </tr>
  <?endforeach?>
 </tbody>
</table>

收件人
消息体
日期
地位
新脚本/附加脚本

<script>
    $(document).on("click", ".open-MessageBodyFill", function () {
    var MessageBodyFull = $(this).data('id');
    $(".modal-body #messageBodyFull").val( MessageBodyFull );
    document.getElementById("messageBodyFull").innerHTML = MessageBodyFull;
    });
</script>

$(文档)。在(“单击“,”上。打开MessageBodyFill”,函数(){
var MessageBodyFull=$(this.data('id');
$(“.modal body#messageBodyFull”).val(messageBodyFull);
document.getElementById(“messageBodyFull”).innerHTML=messageBodyFull;
});
模态

<div class="modal fade" id="messageBodyFull" tabindex="-1" role="dialog" aria-labelledby="messageBodyFull">
 <div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title" id="myModalLabel">STATUS: <?=$feed_item->StatusDescription?></h4>
  </div>
  <div class="modal-body">
     <p type="textarea" name="messageBodyFull" id="messageBodyFull" value=""/> <!-- FIX -->
  </div>      
  <div class="modal-footer">    
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  </div>
</div>

&时代;
地位:

接近


您可能需要添加PHP代码,因为这可能有助于确定原因(即$letter\u feed的变量来自何处)。感谢@Reisclef,添加了模型和控制器。不需要手动转义,是否可以使用准备好的语句?它们通常非常干净,大大降低了出错的风险。但是你说你只想要一张唱片?而且,你的标签需要清理。这与Javascript无关,如果您使用的是某种框架,那么应该包括它。
<table id="tableDataset">
 <thead>
  <tr>
     <th><i class="icon-briefcase"></i> Recipient</th>
     <th class="hidden-xs"><i class="icon-question-sign"></i> Message Body</th>
     <th><i class="icon-bookmark"></i> Date</th>
     <th><i class="icon-bell"></i> Status</th>
  </tr>
</thead>
<tbody>
  <?foreach($letter_feed as $feed_item): ?>
     <tr>
        <td><?=$feed_item->Recipient?></td>
       <!-- FIX --> <td class="hidden-xs"><?=$feed_item->MessageBody?> <a href="#messageBodyFull" class="open-MessageBodyFill btn btn-primary"  data-id="<?=$feed_item->MessageBodyFull?>" data-toggle="modal">Full Message</a></td>  
        <td><?=$feed_item->Created?> </td>
        <td><?=$feed_item->StatusDescription?></td>
     </tr>
  <?endforeach?>
 </tbody>
</table>
<script>
    $(document).on("click", ".open-MessageBodyFill", function () {
    var MessageBodyFull = $(this).data('id');
    $(".modal-body #messageBodyFull").val( MessageBodyFull );
    document.getElementById("messageBodyFull").innerHTML = MessageBodyFull;
    });
</script>
<div class="modal fade" id="messageBodyFull" tabindex="-1" role="dialog" aria-labelledby="messageBodyFull">
 <div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title" id="myModalLabel">STATUS: <?=$feed_item->StatusDescription?></h4>
  </div>
  <div class="modal-body">
     <p type="textarea" name="messageBodyFull" id="messageBodyFull" value=""/> <!-- FIX -->
  </div>      
  <div class="modal-footer">    
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  </div>
</div>