• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is session->userdata supposed to return an array?

$id = 1;
$custom_session_data = array('id' => $id);
$id = $this->session->userdata('id');
Array ( [0] => stdClass Object ( [id] => 1 ) )
I was hoping to get the data as int/str. Am I doing something wrong or this is supposed to be like this? If yes, then is there a way to extract the wanted int without getting 'messy'?

If I use that same code here, I get "int 1" returned.

The CI session library doesn't convert data, and it certainly doesn't create objects. Are you using a custom session library?

No custom library. Just the default one, autoloaded.

Oh my, I've given false information in the first post. Apparently the array originates straight from the database.
$query = $this->db->query("SELECT id FROM users WHERE user = 'asd'");
$id = $query->result();

I'm brand new to CI, so I might be oblivious about correct syntax etc. Any ideas?

See the user guide.

$query->result() returns an array of objects, one for each record in the resultset. You should be doing something like
$query = $this->db->query("SELECT id FROM users WHERE user = 'asd'");

if ($query->num_rows() > 0)
    $row = $query->row();
    $id = $row->id;
    $id = FALSE;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.