如何使用编码器加载用户数据



当我使用不同的用户帐户时,它仍然从数据库加载相同的数据。我想只显示特定用户的数据。如何加载特定用户的数据?谢谢你的回复。

这是我使用ajax查询的视图。

//loading the content
$(document).ready(function(){
{
$.ajax({
url:"<?php echo base_url(); ?>kpi/loaddatatest",
dataType:"JSON",
method:"post",
success:function(data){
//Table will create when the ## ##     
var html = '<tr>';  
html += '<td id="kpi_description" contenteditable placeholder="Enter your KPI"></td>';
html += '<td id="kra_description" contenteditable placeholder="Enter your KRA"></td>';
html += '<td id="kpi_weight" contenteditable></td>';
html += '<td></td>';
html += '<td></td>';
html += '<td><button type="button" name="btn_add" id="btn_add" class="btn btn-xs btn- 
success"><span class="glyphicon glyphicon-plus">+</span></button></td></tr>';
for(var count = 0; count < data.length; count++)    
{

html += '<tr>';
html += '<td class="table_data" data-row_id="'+data[count].id+'" data- 
column_name="kpi_description" contenteditable>'+data[count].kpi_description+'</td>';
html += '<td class="table_data" data-row_id="'+data[count].id+'" data- 
column_name="kra_description" contenteditable>'+data[count].kra_description+'</td>';
html += '<td class="table_data" data-row_id="'+data[count].id+'" data- 
column_name="kpi_weight" disabled>'+data[count].kpi_weight+'</td>';
html += '<td></td>';
html += '<td></td>';
html += '<td><button type="button" name="delete_btn" id="'+data[count].id+'" class="btn 
btn-xs btn-danger btn_delete"><span class="glyphicon glyphicon-remove">x</span></button> 
</td></tr>';
}
$('#testtable').html(html);

}
});
}

这是我的控制器:

public function loaddatatest()
{

$data = $this->Kpi_model->loaddatatest();

echo json_encode($data);
}
这是我的模型:
public function loaddatatest()
{

$this->db->order_by('id', 'ASCE');
$data = $this->db->get('kpi_result'); 

if($data->num_rows()>0)
{
return $data->result();
}
else
{
return false;
}
}

要查询特定的用户,请确保您的数据库中有id_user,当查询可以在loaddatatest()函数中使用get_where()完成时。

$this->db->get_where('user_id', array('user_id => $user_id))

并通过loaddatatest可以通过特定用户id()这样的论点

$data = $this->Kpi_model->loaddatatest($user_id);

最新更新