I am calling a function twice from two different functions, But for one of the function it says "trying to get property of non-object" first function is
我从两个不同的函数调用一个函数两次,但对于其中一个函数,它说“试图获取非对象的属性”第一个函数是
$sql=$this->db->query("select * from gl_events where entry_id='$entry_id'");
if($sql->num_rows() > 0)
{
$row3=$sql->row();
$event_respond[] =
array(
'entry_id'=>$row3->entry_id,
'event_title'=>$row3->event_title,
'location'=>$row3->event_loc_add_ln1,
'location1'=>$row3->event_loc_add_ln2,
'start'=>$row3->event_start_date,
'start1'=>$row3->event_start_time,
'created'=>$row3->user_id,
'about'=>$row3->event_descr,
'end'=>$row3->event_end_time,
'end1' => $row3->event_end_time,
'userid'=>$row3->user_id,
//here the function goes to gl_get_att function and
//calls gl_getusername function,
'attend'=>$this->gl_get_att($row3->entry_id),
// here it calls gl_getusername function directly
'username'=>$this->gl_getusername($row3->user_id)
);
}
gl_get_att definition:
gl_get_att定义:
public function gl_get_att($entry_id)
{
$query=$this->db->query("select * from gl_event_participants where event_id='$entry_id'");
//echo "select * from gl_event_participants where event_id='$entry_id'";
$row1=$query->row();
foreach($query->result() as $row)
{
$data[]= array(
'user_id'=>$row->user_id,
'username'=>$this->gl_getusername($row->user_id)// here it calls get username function
);
}
//print_r($data[1]);
//print_r($data[0]);
return $data;
}
gl_getusername definition:
gl_getusername定义:
public function gl_getusername($user_id)
{
$query=$this->db->query("select user_name from gl_user where user_id = '$user_id'");
$row1=$query->row();
//print_r($row1->user_name);
return $row1->user_name; //This is line 396
}
Now for gl_get_att its returning the proper values but for the first function where i have called it directly its not working
现在对于gl_get_att,它返回正确的值但是对于我直接调用它的第一个函数它不起作用
error message: A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: events/gl_event_model.php
Line Number: 396
line 396 is marked above
第396行标在上面
This was working fine on saturday after the weekend its not working !!! strange
星期六这周末工作正常,它不工作!奇怪
1 个解决方案
#1
3
You aren't checking to see if $query
is valid, or if $query->row() returns an object. This error would be generated if the passed in $entity_id
is not found in the database.
您没有检查$ query是否有效,或者$ query-> row()是否返回一个对象。如果在数据库中找不到传入的$ entity_id,则会生成此错误。
#1
3
You aren't checking to see if $query
is valid, or if $query->row() returns an object. This error would be generated if the passed in $entity_id
is not found in the database.
您没有检查$ query是否有效,或者$ query-> row()是否返回一个对象。如果在数据库中找不到传入的$ entity_id,则会生成此错误。