Welcome Guest, Not a member yet? Register   Sign In
session set_userdata and associative array


I have a problem i need to pass multiple value names (e.g. properrty_id) with differnet values (e.g. 1,3,5,9) to a DB session. So i run set_userdata, but this only allows me to pass a name of "property_id". If i call this twice the first value is overwritten.

So one name but potentialy multiple values. Shhould i pass this as an associative array such as property_id[], and use userdata the same way?

Any advice on how to handle this ?

Quote:I have a problem i need to pass multiple value names (e.g. properrty_id)


I'm somewhat lost. What exactly are the multiple value names you are talking about? You only mention one value name, not multiple. Either way, set_userdata lets you pass it an array of data to set or a single value. For example:

$data = array(
              'property_id'  => array(1, 3, 5, 9),
              'name'     => 'some value',
              'description' => 'some description'


Hey guys, I did what OwanH said but I don't know how to acces to the third item of the 'property_id' array on my session, I mean

$this->session->userdata('property_id') ... ???


Hi alejandronanez,

$this->session->userdata(‘property_id’) would return the entire array stored in the session for the 'property_id' variable. All you need to do after that is access the elements like a regular PHP array.

$value = $this->session->userdata(‘property_id’);
print $value[2];  // access the third item of the array 'property_id';

Please remember that CodeIgniter is NOT another language, it is just a programming framework written in PHP.

Theme © iAndrew 2016 - Forum software by © MyBB