如何使用Codeigniter在弹出模式中获取行详细信息 [英] How to Fetch row details in popup modal using codeigniter

查看:54
本文介绍了如何使用Codeigniter在弹出模式中获取行详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已使用引导卡从数据库显示了数据.所有这些卡都具有阅读更多"按钮.一旦单击Read More,模态应获取特定的行详细信息并显示.视图如下图所示

Have displayed data from database using bootstrap card. All these cards have Read more buttons. Once click on the Read More the modal should fetch that specific row details and display. The view is as shown below

代码如下:

使用卡查看代码

<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='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#whatwedo'>Read More</a>";
        echo "</div>";
        echo "</div>";
        echo "</div>";
    }
?>

应该加载的模态代码:

<?php 

    $query = $this->db->query("SELECT * FROM services_offered");
    foreach ($query->result() as $row) {
        
        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 "..";
        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>";
    }
 ?>

控制器代码

public function fetchDetails($id)
    {
        $this->db->where('id',$id);
        $query = $this->db->query("SELECT * FROM services_offered");
        return $query->result();
    }

推荐答案

您应为模式或服务的每个模式赋予不同的ID,每个服务的ID必须唯一.

You should give the modal different ID each modal or services, ID must unique for each services.

为按钮提供ID

echo "<a href='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#idmodal'>Read More</a>";
           

并为模态赋予相同的ID

and give the modal also the same id

echo "<div class='modal fade' id='idmodal' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";

您可以在数据库中使用服务ID或为其指定唯一名称,以确保按钮和模式具有相同的ID.

you can use services id in your database or give it a unique name make sure the button and the modal have the same id.

这篇关于如何使用Codeigniter在弹出模式中获取行详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆