Jump to content

Archived

This topic is now archived and is closed to further replies.

hazy

session array

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]

Share this post


Link to post
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]

Share this post


Link to post
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!! :)

Share this post


Link to post
Share on other sites

×

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.