我们可以在模态弹出窗口中显示单击时的数据吗?请协助如何使用CodeIgniter完成此操作

zlwx9yxi  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(125)

我正在使用Codeigniter开发一个博客,其中的详细信息显示在一个具有“Read More”特性的引导卡中,代码动态地获取数据,并显示卡中的所有详细信息,但是一旦点击“阅读更多”,它只显示第一行数据。如何在模式弹出窗口中获取点击“阅读更多”按钮的特定行数据?下面是获取数据并在卡片中显示的代码:

<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'>&times;</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
    }
?>

还有什么可以做到的?请协助。谢谢

jrcvhitl

jrcvhitl1#

您应该给予每组按钮和模态
用于按钮

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'>";
}

如果您没有ID,可以执行此操作

$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++;
    }

您将获得相同的结果。

相关问题