gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:30:44 25 4
gpt4 key购买 nike

我的代码无法显示有关我选择的一个用户的详细信息,它总是显示有关表上最后一个用户的详细信息,无论我点击谁。我认为我的问题是我的代码无法意识到我点击了谁,所以它只选择最后一个用户。你能看看并帮助我解决我的问题吗?这是我的观点(我在 Bootstrap 模态上使用模态来显示结果)

<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>

这是我的代码:

   <?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
}
?>

这是我的 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);
}

这是我的模型

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;
}
}

最佳答案

嘿,在你的 Controller 中创建一个名为 Modal.php 的文件,并将这段代码粘贴到这里

<?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);
}
}

和这是为了查看所有用户

<?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 } ?>

还有一些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>

和一些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>

最后在您的 application/views 文件夹中创建一个名为 details.php 的文件并写入

<?php
$this->db->where('username', $param2);
$query = $this->db->get('user');

$details = $query->row();

print_r($details);
?>

关于php - 无法显示有关用户的详细信息(codeigniter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34984773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com