我有一个显示的名称列表,当用户点击编辑时,它会打开一个带有html表单的对话框。然后,该表单将显示从mysql表中检索的数据的值。但是我对如何实现这一点感到非常困惑。这是我到目前为止所做的。
查看
<table class="table">
<thead>
<tr>
<th>No.</th>
<th>Organisation</th>
<th>First Name</th>
<th>Last Name</th>
<th>Privilege Level</th>
<th>Date Added</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php $offset = $this->uri->segment(4,0)+1; ?>
<?php foreach($user as $row): ?>
<tr data-id="<?php echo $row->id; ?>">
<td><?php echo $offset++; ?></td>
<td><?php echo $row->company; ?></td>
<td><?php echo $row->firstname; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->privilege; ?></td>
<td><?php echo $row->date_added; ?></td>
<td><input type="hidden" name="id" value="<?php echo $row->id; ?>"/><input type="hidden" name="company" value="<?php echo $row->id; ?>"/><input type="hidden" name="set" value="edit"/><input type="button" class="editlink" value="Edit"/></td>
<td><input type="hidden" name="id" value="<?php echo $row->id; ?>"/><input type="hidden" name="company" value="<?php echo $row->id; ?>"/><input type="hidden" name="set" value="delete"/><input type="button" class="deletelink" value="Delete"/></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo $links; ?>
</div>
<div id="edit-dialog">
<?php echo form_open('manager/users/edit_user'); ?>
<p>First Name : <input type="text" name="firstname"/></p>
<p>Last Name : <input type="text" name="lastname"/></p>
<p>NRIC : <input type="text" name="nric"/></p>
<p>Address : <input type="text" name="address"/></p>
<p>Username : <input type="text" name="username"/></p>
</form>
</div>
我的控制器
function get_user()
{
$id = $this->input->post('id');
$this->load->model('user');
$data = $this->user->retrieve($id);
}
我的模特
public function generate($id)
{
$this->db->where('id',$id);
$query = $this->db->get($this->tablename);
if($query->num_rows()==1)
{
return $query->result();
}
else
{
return $query->result();
}
}
我的Jquery / AJAX
$('.editlink').on('click', function() {
var user_id = $(this).parent().parent('tr').attr('data-id');
$.ajax({
url: 'http://localhost/manager/users/get_user',
type: 'POST',
dataType:'text',
data:{'id':user_id},
cache:false,
success:function(result){
$("#edit-dialog").show();
console.log($.parseJSON(result));
$("#edit-dialog").dialog({
title: 'Edit User',
width: 400,
height: 500,
draggable: false,
modal: true,
dialogClass: "edit-user",
open: function(){
},
buttons: [
{
text: 'Update',
click: function() {
$('#manipulate_user').submit();
}
},
{
text: 'Cancel',
click: function() {
$(this).dialog('close');
}
}
]
});
}});
});
});