【发布时间】:2013-04-04 18:11:40
【问题描述】:
我正在从数据库中进行选择,并且数据已成功返回。我只是不确定如何访问数组的元素,例如用户名或名称等。这是输出:
Array ( [0] => stdClass Object ( [id] => 9 [fullname] => خالد الغامدي [会员] => 免费 [用户名] => kkkkk [密码] => 16d7a4fca7442dda3ad93c9a726597e4 [电子邮件] => someone@gmail.com [关于] => [城市] => 利雅得 [profilepic] => /home2/sdds/public_html/uploads/Red_velvet_cupcakes_with_roses.jpgRed_velvet_cupcakes_with_roses.jpg [手机] => [电话] => [地址] => [画廊链接] => ) )
这是模型中返回上述内容的代码:
public function login()
{
$this->db->select('*');
$this->db->from('members');
$this->db->where('username', $this->input->post('username'));
$this->db->where('password', md5($this->input->post('password')));
$query = $this->db->get();
return $query->result();
}
那么在这里做什么呢?在此先感谢
【问题讨论】:
-
foreach 通过结果哟。
-
给了我这个:消息:stdClass 类的对象无法转换为字符串
-
$query->result()返回一个对象,而不是一个数组。如果需要数组,请改用$query->result_array()。这是一个常见的错误:)