【发布时间】:2017-06-07 05:28:48
【问题描述】:
理想情况下,在我的数据库表中,我有用户名、姓名、位置、电子邮件。
现在我的 view.php 中有一个表,它从数据库返回值。
Table 标头由名称、用户名和更多信息组成,其中 name 和 username 直接来自数据库,而更多信息 将为每一行提供一个按钮。单击该按钮时,应在弹出窗口中显示位置和电子邮件。
问题:当专门点击按钮时,如何检索用户的位置和电子邮件?
例子:
user1,joe doe,[按钮] -> user1 位置,user1@email.com
user2,jay doe,[按钮] -> user2 位置,user2@email.com
代码:p.s.代码包括分页。
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 添加了。
标签: javascript php codeigniter