adding to existing session |
[eluser]nuttynibbles[/eluser]
how do i add data to existing session. e.g: the current session contain this... $sessiontag=array('sessid'=>'1234abc','a1'=>'apple','a2'=>'boy'); and now i wanna add another value 'a3'=>'cat' into the session array, how can i approach this problem.
[eluser]Pascal Kriete[/eluser]
Umm.. set_userdata() ? Try out the user guide, it really is quite useful sometimes.
[eluser]nuttynibbles[/eluser]
okie this is what i did. 1. i created a session in page1.php Code: $sessiontag=array('sessiontag'=>array('sessiontagid'=>'abc123') 2. then page1.php will be redirected to page2.php 3. in page2.php, i have a button to insert session values of unique key and the new value. this is what i did: Code: /*controller*/ 3. each time i did an insert, i realized the unique key and value were overwritten. it did not add a new array. why is this so? thanks help.
[eluser]frietkot[/eluser]
You could get the data from the existing session into an array and then push the new data into that array. Next step is to make a new session with the new array with all the data in it. Something like that?
[eluser]nuttynibbles[/eluser]
yup that was what i did. I took out the array and insert new value. But instead of adding new row of value, it overwrite the previous value. the above code i posted is what i have done.
[eluser]Randy Casburn[/eluser]
[quote author="nuttynibbles" date="1223499079"]yup that was what i did. I took out the array and insert new value. But instead of adding new row of value, it overwrite the previous value. the above code i posted is what i have done.[/quote] Wow....This is much less a CI session thing than a basic array thing... @NuttY -- have you ever heard of array_pop, array_push, array_shift, and array_unshift ? Code: /*controller*/ You can test this as I'm not exactly sure this will work, but this will get you darn close. Try this please. Randy
[eluser]Randy Casburn[/eluser]
[quote author="frietkot" date="1223555510"]Thats what i ment to say Randy. Thanks[/quote] Ahh...I see. I put up some code just so nutty could see the difference. I hope it was helpful. Randy
[eluser]nuttynibbles[/eluser]
hey both, i managed to dynamically add values to array. however, i encounter some problem while doing so. because this function is done when im login, in the process, i realise my session got destroyed and i was logout of the system. im not sure why but i am still investigating. |
Welcome Guest, Not a member yet? Register Sign In |