Welcome Guest, Not a member yet? Register   Sign In
two dimension session issue with codeigniter
#1

[eluser]deeptik[/eluser]
I want to store two dimensional array in session, where i keep creating the array through a function call.

I am trying with this code

Code:
function nextQuestion($questionId,$response){

$this->session->set_userdata("res[$questionId][]"),$response);

}

but this is not creating a two dimensional array
#2

[eluser]Aken[/eluser]
The first parameter needs to be a standard string, since it will act as a key in an associative array which makes up the session data.

You can retrieve and manipulate an array that's already in your session if that's what you want to do. But the key has to be a normal string.
#3

[eluser]deeptik[/eluser]
[quote author="Aken" date="1338007416"]The first parameter needs to be a standard string, since it will act as a key in an associative array which makes up the session data.

You can retrieve and manipulate an array that's already in your session if that's what you want to do. But the key has to be a normal string.[/quote]


I have tried that also but that not working with codeigniter session

can you write the code for the same

Please help me
#4

[eluser]Aken[/eluser]
1) Retrieve the session item using $this->session->userdata('item'); Or set it if it doesn't exist yet.

2) Add something to the array.

3) Store it again.

Read the user guide to figure out how to apply those steps. Smile
#5

[eluser]Sanjay Sarvaiya[/eluser]
Hi I had same problem and fixed with this.
Code:
$ar= ($this->session->userdata('res')) ? $this->session->userdata('res') : array('que');
$que = 'new question';
array_push($ar, $que);
$this->session->set_userdata('res', $ar);

hope thats help.




Theme © iAndrew 2016 - Forum software by © MyBB