dtcuv8044 2016-01-25 03:48
浏览 17
已采纳

无法显示有关用户的详细信息(codeigniter)

my code can not show detail about one user that i choose, it just always shows the detail about the last user on the table no matter who i am click on. I think my problem is my code can not realize who did i click on so it just choose the last user. Can you have look and help me solve my problem. This is my view (i am using modal on bootstrap modal to show the result)

<div class="modal fade" id="userDetail" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <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="exampleModalLabel"><span class = "glyphicon glyphicon-pencil"></span> Edit</h4>
    </div>
    <div class="modal-body">
      <div class="form-group">
        <?php echo form_open('admin/update_event'); ?>
        <p><b>User Name</b></p><p><input class = "form-control" placeholder = "User name" type='text' 
        name = 'event_name' id = 'event_name' readonly value = "<?php echo $r->username;?>"></p>

        <p><b>Email</b></p><p><input class = "form-control" readonly placeholder = "Email" type='text' 
        name = 'event_code' id = 'event_code' readonly value = "<?php echo $r->email;?>"></p>
        <hr>
        <p><b>First Name</b></p><p><input class = "form-control" readonly placeholder="First Name of member" type='text' 
        name = 'event_size' id = 'event_size' readonly value = "<?php echo $r->firstname;?>"></p>

        <p><b>Last Name</b></p><p><input class = "form-control" readonly placeholder="Last Name" type='text' 
        name = 'lastname' readonly value = "<?php echo $r->lastname;?>"></p>

        <p><b>Level</b></p><p>
        <select class = "form-control">
            <option selected disabled><?php if($r->level==1){
                    echo 'Admin';
                }else{
                    echo 'Member';
                } ?></option>
            <option value="1" <?php echo ($r->level == 1)?:""; ?>>Administrator</option>
            <option value="0" <?php echo ($r->level == 2)?:""; ?>>Member</option>
        </select>
        </p>
        <p><b>Status</b></p><p><select class = "form-control">
            <option selected disabled><?php if($r->sta==1){
                    echo 'Deactive';
                }else{
                    echo 'Active';
                } ?></option>
            <option value="1" <?php echo ($r->sta == 1)?:""; ?>>Deactive</option>
            <option value="0" <?php echo ($r->level == 0)?:""; ?>>Active</option>
        </select></p>

    </div>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <input type = "submit" value = "Update" class = "btn btn-primary">
    <?php echo form_close();?>
</div>

and this is my code:

   <?php 
$count = 1;

foreach ($ro as $r) 
{
    ?>
    <tr>
        <td scope="row"><?php echo $count++?></td>

        <td>
            <a href="#"  data-toggle="modal" data-target="#userDetail">
                <?php echo $r->username; ?>
            </a>
        </td>
        <td><?php echo $r->email; ?></td>
        <td><?php echo $r->firstname; ?></td>
        <td><?php echo $r->lastname; ?></td>
        <td><?php $r->level; 
            if($r->level==1){
                echo '<strong><p style="color:#0047b3;">Admin</p></strong>';
            }else{
             echo '<strong><p style="color:#993300;">Member</p></strong>';
         }
         ?></td>
     </tr>
     <?php
 }
 ?>

This is my controller

function admins_area(){
    $data['main_content'] = 'backend/home/admins_area';
    $this->load->model('membership_model');
    $data['rows']= $this->membership_model->getUserData();
    $data['ro']= $this->membership_model->getAllUserData();
    $this->load->view('includes/admin/template', $data);
}

And this is my model

function getUserData(){
    $this->db->where('username', $this->session->userdata('username'));
    $query = $this->db->get('user');
    if($query->num_rows()>0){
        foreach ($query->result() as $row){
            $data[]=$row;
        }
        return $data;
    }
}
function getAllUserData(){
    $query = $this->db->get('user');
    if($query->num_rows()>0){
        foreach ($query->result() as $row) {
            $data[]=$row;
        }
        return $data;
    }
}   
  • 写回答

1条回答 默认 最新

  • doudai8783 2016-01-25 07:33
    关注

    Hey Create a file named Modal.php in your controller and paste this code in this

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Modal extends CI_Controller {
    
    
        function __construct()
        {
            parent::__construct();
            $this->load->database();        
            $this->load->helper(array('form', 'url'));
            /*cache control*/
            $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
            $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
            $this->output->set_header('Pragma: no-cache');
            $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
        }
    
        /***default functin, redirects to login page if no admin logged in yet***/
        public function index()
        {
    
        }
    
    
        /*
        *   $page_name      =   The name of page
        */
        function popup($page_name = '' , $param2 = '' , $param3 = '')
        {
            //$account_type             =   $this->session->userdata('login_type');
            $page_data['param2']        =   $param2;
            $page_data['param3']        =   $param3;
            $this->load->view( $page_name.'.php' ,$page_data);
        }
    }
    

    and this to see all users

    <?php 
    $count = 1;
    
    foreach ($ro as $r) 
    {
        ?>
        <tr>
            <td scope="row"><?php echo $count++?></td>
    
            <td>
                    <?php echo $r->username; ?>
            </td>
    <td>
    <button onclick="showAjaxModal('<?php echo site_url(); ?>/modal/popup/details/<?php echo $r->username; ?>')">Details</button>
    </td>
    </tr><?php } ?>
    

    And some html

     <div class="modal fade" id="modal_ajax" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog" >
                <div class="modal-content">
    
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title">User Details</h4>
                    </div>
    
                    <div class="modal-body">
    
    
    
                    </div>
    
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    

    and some javascript

    <script>
    function showAjaxModal(url)
        {
            // SHOW AJAX RESPONSE ON REQUEST SUCCESS
            jQuery.ajax({
                url: url,
                success: function(response)
                {
                    jQuery('#modal_ajax .modal-body').html(response);                         
                    jQuery('#modal_ajax').modal('show', {
                      backdrop: 'static',
                      keyboard: false
                    });
    
                }
            });
        }
    </script>
    

    And finally create a file named details.php in your application/views folder and Write

    <?php
    $this->db->where('username', $param2);
        $query = $this->db->get('user');
    
    $details = $query->row();
    
    print_r($details);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。