Welcome Guest, Not a member yet? Register   Sign In
Why can't I access return value of db->get properly?
#1

[eluser]inktri[/eluser]
sql table: users

user controller, within index() function, :
Code:
$data['query'] = $this->db->get('users');
$this->load->view('user_view', $data);

user view:
Quote:<?php foreach($query->result() as $user): ?>
<pre>&lt;?php $user->username ?&gt;</pre>
&lt;?php endforeach; ?&gt;

yields nothing

but

Code:
&lt;?php foreach($query->result() as $user): ?&gt;
<pre>&lt;?php var_dump($user) ?&gt;</pre>
&lt;?php endforeach; ?&gt;

shows
Code:
object(stdClass)#13 (8) {
  ["id"]=>
  string(1) "1"
  ["username"]=>
  string(6) "inktri"
  ["password"]=>
  string(32) "eba3cbb6f3b8265ee302e2339fc83dbc"
  ["birthday"]=>
  string(10) "2006-05-00"
  ["gender"]=>
  string(1) "m"
  ["city_id"]=>
  string(1) "1"
  ["pic"]=>
  string(1) "1"
}


Why can't I access the username with $user->username?

thanks for the help
#2

[eluser]mironcho[/eluser]
Missing 'echo' or similar. Try:
Code:
<pre>&lt;?php echo $user->username ?&gt;</pre>
or
Code:
<pre>&lt;?= $user->username ?&gt;</pre>




Theme © iAndrew 2016 - Forum software by © MyBB