Jump to content


Photo

session array


  • Please log in to reply
2 replies to this topic

#1 hazy

hazy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 April 2006 - 02:12 AM

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?!

$a = 0;
while ($Array1[$a]){
    $_SESSION['userinfo']['array'] = array($a => $Array1[$a]);
         echo $_SESSION['userinfo']['array'][0];
    $a = $a + 1;
}


#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 28 April 2006 - 03:39 AM

// 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/>';

}


#3 hazy

hazy
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 29 April 2006 - 03:05 AM

[!--quoteo(post=369453:date=Apr 27 2006, 11:39 PM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 27 2006, 11:39 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
// 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/>';

}
[/quote]

Thank you!! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users