2017-01-22 22 views
1

理想情况下,在我的数据库表中,我有用户名,名称,位置,电子邮件。Codeigniter:使用按钮点击查看更多数据库中的数据

现在我在我的view.php中有一张表,它从数据库返回值。

头包含名称,用户名等详细信息的地方用户名从数据库中直接来同时更多信息将有各行的按钮。点击按钮时,应该弹出显示位置和电子邮件。

问题:如何专门点击按钮时检索用户的位置和电子邮件?

实施例:

用户1,乔DOE,[按钮] - >用户1的位置,[email protected]

USER2,松鸦DOE,[按钮] - > USER2位置,用户2 @电子邮件.com

代码:ps代码包含分页。

Controller.php这样

function pagination() { 
     $config = array(); 
     $config['base_url'] = base_url() . "controller/pagination"; 
     $total_row = $this->model->record_count(); 
     $config["total_rows"] = $total_row; 
     $config["per_page"] = 8; 
     $config['uri_segment'] = 3; 
     /* $config['use_page_numbers'] = TRUE; */ 
     $config['num_links'] = $total_row; 
     $config['cur_tag_open'] = '&nbsp;<a class="current">'; 
     $config['cur_tag_close'] = '</a>'; 
     $config['next_link'] = '<span aria-hidden="true">&raquo;</span>'; 
     $config['prev_link'] = '<span aria-hidden="true">&laquo;</span>'; 

     $this->pagination->initialize($config); 

     $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 


     $data["results"] = $this->model->fetch_data($config["per_page"], $page); 
     $str_links = $this->pagination->create_links(); 
     $data["links"] = explode('&nbsp;', $str_links); 

     // View data according to array. 
     $this->load->view("view-employees", $data); 
    } 

model.php

public function record_count() { 
    return $this->db->count_all('users'); 
} 

public function fetch_data($limit, $start) { 
    $this->db->limit($limit, $start); 
    $query = $this->db->get('users'); 

    if ($query->num_rows() > 0) { 
     foreach ($query->result() as $row) { 
      $data[] = $row; 
     } 

     return $data; 
    } 
    return false; 
} 

view.php

<tr> 
    <th>username</th> 
    <th>name</th> 
    <th>more</th> 
</tr> 
<tr> 
    <?php foreach ($results as $data) { ?> 
    <td><?php echo $data->username; ?></td> 
    <td><?php echo $data->name; ?></td> 
    <td> 
     <button type='button' class='btn'> 
      <?php echo $data->location; 
       echo $data->email; 
      ?> 
     </button> 
    </td> 
</tr> 
+0

添加一些代码将是不错.. –

+0

@AbdullaNilam增加。 – blakcat7

回答

0
  1. 你可以写一个笨控制器将返回电子邮件和位置
  2. 然后你写JavaScript的功能,这将调用该控制器检索数据asJSON-数据

两个,写控制器返回JSON和示例如何调用JS从该控制器可以在这里找到:

Code Igniter - How to return Json response from controller

+0

我已将我的帖子与代码一起更新。你可以检查吗? – blakcat7

0

尝试这样的..

MODEL:

public function record_count() { 
    return $this->db->count_all('users'); 
} 

public function fetch_data($limit, $start) { 
    $this->db->limit($limit, $start); 
    $query = $this->db->get('users'); 

    if ($query->num_rows() > 0) { 
     return $query->result_array(); 
     } 


    } 
    return false; 
} 

查看:

<tr> 
    <th>username</th> 
    <th>name</th> 
    <th>more</th> 
</tr> 
<tr> 
    <?php foreach ($results as $data) { ?> 
    <td><?php echo $data['username']; ?></td> 
    <td><?php echo $data['name']; ?></td> 
    <td> 
     <button type='button' class='btn'> 
      <?php echo $data['location']; 
       echo $data['email']; 
      ?> 
     </button> 
    </td> 
<?php } ?> 
</tr> 
+0

嗨,谢谢你的回应。是的,如果直接回显到按钮,它确实可以很好地工作。有没有可能的方式在弹出窗口中回显它? – blakcat7

+0

是的,你可以学习引导模型。设置一些HTML属性..我希望你能做到这一点。 –

+0

在这里看到关于模型http://www.w3schools.com/bootstrap/bootstrap_modal.asp –

相关问题