晚上好。即时通讯新手在代码点燃框架。我想问一下如何用代码点火器调用特定的数据。我的下面的代码打算从我的数据库中调用图片的名字。如何使用代码点火器调用数据库中的特定数据?
此我的模型
function profile_picture(){
$username = $this->session->userdata('name');
$this->db->select('pict_name');
$this->db->from('picture');
$this->db->where('username="$username"');
$this->db->limit(1);
$query = $this->db->get();
return $query;
}
这是我的控制器
public function v_profile(){
$data['ppicture'] = $this->m_profile->profile_picture()->result();
$data['profile'] = "profile";
$this->load->view('header',$data);
$this->load->view('profile',$data);
$this->load->view('footer',$data);
}
这是我的视图
<img src="<?php echo base_url()."assets/img/".$ppicture; ?>" class="img-rounded" >
上面的代码显示错误:数组到字符串的转换。我该如何解决它?感谢
如果他有超过一排? – chad
OP正在使用'$ this-> db-> limit(1);',所以OP期待单行数据回报:) –
没有注意到!好答案! – chad