理想情况下,在我的数据库表中,我有用户名,名称,位置,电子邮件。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'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = '<span aria-hidden="true">»</span>';
$config['prev_link'] = '<span aria-hidden="true">«</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(' ', $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>
添加一些代码将是不错.. –
@AbdullaNilam增加。 – blakcat7