[英]ERROR Message: Trying to get property of non-object in CODEIGNITER
I'm trying to get data from a certain table where the member id from a dropdown lis value is equal to the id from the other table. 我正在尝试从某个特定表中获取数据,其中下拉lis值中的成员ID等于另一个表中的ID。 And i'm using jquery ajax also. 而且我也在使用jquery ajax。
Here's my controller transactions.php 这是我的控制器transaction.php
function getdataload(){
$this->db->where('member',$this->input->post('member'));
echo $this->db->get('loading_service')->row()->member;
}
And here's is my view.php 这是我的view.php
<label for="member">Member</label>
<select class="form-control" id="member" name="member" required onchange="showCustomer(this.value)">
<option selected="" value="">--select--</option>
<?php foreach ($members as $row): ?>
<option value="<?php echo $row->mem_id; ?>"><?php echo ucwords($row->mem_fname.' '.$row->mem_lname) ?></option>
<?php endforeach ?>
</select>
<p class="help-block text-danger" style="margin-left: 600px; margin-top: -450px; color: red;"><span id="select_member"> </span></p>
<script>
$('#member').on('change',function(){
$.post('<?php echo base_url("transactions/getdataload")?>',
{
mem_id:$(this).val()
}).done(function(res)
{
$('#select_member').text(res);
});
});
</script>
Please help me with this guys: 请帮我这些家伙:
The first thing to do is make sure you are getting results from your query. 首先要做的是确保您从查询中得到结果。 Try something like 尝试类似
$query = $this->db->get(...);
if ($query->num_rows() > 0) {
return json_encode($query->result());
} else {
return "No data found";
}
then handle the no data error gracefully in your ajax success code. 然后在ajax成功代码中适当地处理no data错误。 I sort of guessed that you would want your query result returned as json. 我有点猜想您希望查询结果作为json返回。
Try: model 尝试: 模型
function getData()
{
$this->db->select('field_name');
$this->db->from('loading_service');
$this->db->where('member',$this->input->post('member'));
$query=$this->db->get();
return $query->row();
}
Controller 控制者
function getdataload(){
$data['member'] = $this->model_name->getData();
$this->load->view("view_name",$data);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.