我正在使用 Codeigniter 开发一个博客,其中详细信息通过“阅读更多”功能显示在引导卡中。该代码动态获取数据并显示卡中的所有详细信息,但单击“阅读更多”后,它仅显示第一行数据。可以采取什么措施来获取单击“阅读更多”按钮的模式弹出窗口中的特定行数据? 这是获取数据并在卡片中显示的代码:
<div class="row clearfix">
<?php
$query = $this->db->query("SELECT * FROM services_offered LIMIT 15");
foreach ($query->result() as $row) {
echo "<div class='col-lg-4 bottommargin-sm'>";
echo "<div class='feature-box media-box fbox-bg'>";
echo "<div class='fbox-media'>";
echo "<a href='#'><img src='$row->swo_images' alt='Featured Box Image' style='height:250px; width:450px;'></a></div>";
echo "<div class='fbox-content fbox-content-lg'>";
$string = $row->swo_brief_intro;
$string = word_limiter($string, 15);
echo "<h3 class='nott ls0 font-weight-semibold'>$row->swo_image_heading<span class='subtitle font-secondary font-weight-light ls0'>$string</span></h3>";
echo "<a href='#' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#whatwedo'>Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
// section for modal starts here
echo "<div class='modal fade' id='whatwedo' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog'>";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<h5 class='modal-title' id='exampleModalLabel'>$row->swo_image_heading</h5>";
echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
echo "<span aria-hidden='true'>×</span>";
echo "</button>";
echo "</div>";
echo "<div class='modal-body'>";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-secondary' data-dismiss='modal'>Close</button>";
echo "<button type='button' class='btn btn-primary'>Save changes</button>";
echo " </div>";
echo "</div>";
echo "</div>";
echo "</div>";
// section for modal starts here
}
?>
还有什么可能?请帮忙。谢谢你
您应该为每组按钮和模式提供不同的 ID
对于按钮
echo "<a href='#' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#modal".$row->id."'>Read More</a>";
对于模态
echo "<div class='modal fade' id='modal".$row->id."' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
因此 1 个阅读更多按钮将与 1 个模态关联
如果你的桌子上有ID,你可以做这样的事情
foreach($data as $dt){
echo "<a href='#' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#modal".$dt->id."'>Read More</a>";
echo "<div class='modal fade' id='modal".$dt->id."' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
}
如果您没有身份证,您可以这样做
$counter = 1;
foreach($data as $dt){
echo ("<a href='#' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#modal".$counter"'>Read More</a>");
echo ("<div class='modal fade' id='modal".$counter"' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>");
counter++;
}
您将获得相同的结果。