Jump to content

session array


hazy

Recommended Posts

I've search the forums... google... and finally my eyes are burning and I am way to tired so I am hoping someone on here can see what I am missing. Basically I am trying to load a session array with another array which was populated by database information.

For some reason I can not get it to work. For some reason the data entered the first time threw the loop seems to 'disappear' after it loops threw the second time. i.e. If I echo $_SESSION['userinfo']['array'][0] on the first time threw the loop it will show the proper data... the second time threw and it throws an UNDEFINED INDEX: 0 at me. Anyone have any ideas?!

[code]$a = 0;
while ($Array1[$a]){
    $_SESSION['userinfo']['array'] = array($a => $Array1[$a]);
         echo $_SESSION['userinfo']['array'][0];
    $a = $a + 1;
}
[/code]
Link to comment
Share on other sites

[code]
// Example of setting the session values
for ($i = 0, cnt=count($Array1); $i < $cnt; $i++) {

    // [] creates a new index automatically
    $_SESSION['userinfo']['array'][] = $Array1[$i]; // or just use: $_SESSION['userinfo'][] = ...

}


// An example of how to display the session values
for ($i = 0, cnt=count($_SESSION['userinfo']['array']); $i < $cnt; $i++) {

    echo "Data $i: ", $_SESSION['userinfo']['array'][$i], '<br/>';

}
[/code]
Link to comment
Share on other sites

[!--quoteo(post=369453:date=Apr 27 2006, 11:39 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 27 2006, 11:39 PM) [snapback]369453[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]
// Example of setting the session values
for ($i = 0, cnt=count($Array1); $i < $cnt; $i++) {

    // [] creates a new index automatically
    $_SESSION['userinfo']['array'][] = $Array1[$i]; // or just use: $_SESSION['userinfo'][] = ...

}
// An example of how to display the session values
for ($i = 0, cnt=count($_SESSION['userinfo']['array']); $i < $cnt; $i++) {

    echo "Data $i: ", $_SESSION['userinfo']['array'][$i], '<br/>';

}
[/code]
[/quote]

Thank you!! :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.