将数组中的值分配给codeigniter中的变量
assigning a value from a array to a variable in codeigniter
我想将数组中的值保存到变量中。以进行 if 条件检查。这是我在模型文件夹中的代码。我得到一个 errormysqli_fetch_array() 期望参数 1 为 mysqli_result,对象给定。但是 $query returns 一个数组值。
public function this_is_try(){
$this->db->select('*');
$this->db->from('partnerprofile');
$this->db->where('User_Id','20');
$query = $this->db->get();
$query->result_array();
$row = mysqli_fetch_array($query);
$user_id = $row['User_Id'];
$agefrom = $row['AgeFrom'];
print $user_id;
exit;
}
试试这个:
public function this_is_try(){
$row = $this->db->select('*')
->from('partnerprofile');
->where('User_Id','20');
->get()->row();
$user_id = $row->User_Id;
$agefrom = $row->AgeFrom;
print $user_id;exit;
}
而不是传递整个 $results(result object)。将 result_object 存储到一个变量并传递它,即 $result=$results[0];
public function this_is_try(){
$this->db->select('*');
$this->db->from('partnerprofile');
$this->db->where('User_Id','20');
$query = $this->db->get();
$results = $query->result();
$result = $results[0];
$user_id=$result->user_id;
$agefrom = $result->AgeFrom;
print $user_id;exit;
}
我想将数组中的值保存到变量中。以进行 if 条件检查。这是我在模型文件夹中的代码。我得到一个 errormysqli_fetch_array() 期望参数 1 为 mysqli_result,对象给定。但是 $query returns 一个数组值。
public function this_is_try(){
$this->db->select('*');
$this->db->from('partnerprofile');
$this->db->where('User_Id','20');
$query = $this->db->get();
$query->result_array();
$row = mysqli_fetch_array($query);
$user_id = $row['User_Id'];
$agefrom = $row['AgeFrom'];
print $user_id;
exit;
}
试试这个:
public function this_is_try(){
$row = $this->db->select('*')
->from('partnerprofile');
->where('User_Id','20');
->get()->row();
$user_id = $row->User_Id;
$agefrom = $row->AgeFrom;
print $user_id;exit;
}
而不是传递整个 $results(result object)。将 result_object 存储到一个变量并传递它,即 $result=$results[0];
public function this_is_try(){
$this->db->select('*');
$this->db->from('partnerprofile');
$this->db->where('User_Id','20');
$query = $this->db->get();
$results = $query->result();
$result = $results[0];
$user_id=$result->user_id;
$agefrom = $result->AgeFrom;
print $user_id;exit;
}