Caislean Posted February 27, 2007 Share Posted February 27, 2007 I'm storing session information in an array. (integer)$arrayElement = 0; while($row = mysql_fetch_array($result)) { $_SESSION['eventID[ . $arrayElement]'] = $row['extid']; $arrayElement++; if (debugInfo) echo "Stored Value: " . $_SESSION['eventID[ .$arrayElement]']; } This code gives the proper output of "Stored Value: 0001, Stored Value: 0002, etc..." But then, if I'm outside the while statement and I attempt to retrieve the values, the elements are empty. For example, if I use: for ($counter = ($_SESSION['eventsPerPage'] - $_SESSION['currentEvent']); $counter < $_SESSION['currentEvent']; $counter++) { echo "Stored Value: " . $_SESSION['eventID[ .$arrayElement]']; } It gives the output "Stored Value: , Stored Value: , etc..." Why are the elements suddenly empty after leaving the while statement? Link to comment https://forums.phpfreaks.com/topic/40392-solved-array-problem-session-array-becomes-empty/ Share on other sites More sharing options...
Orio Posted February 27, 2007 Share Posted February 27, 2007 Do you have session_start() in the beginning of these two pages? Orio. Link to comment https://forums.phpfreaks.com/topic/40392-solved-array-problem-session-array-becomes-empty/#findComment-195438 Share on other sites More sharing options...
Caislean Posted February 27, 2007 Author Share Posted February 27, 2007 Yes, I do have a session start in the code. But the code is pretty long, so I thought I'd sum up the problem. If you want to see the full thing just go http://www.phpfreaks.com/forums/index.php/topic,128253.0.html Link to comment https://forums.phpfreaks.com/topic/40392-solved-array-problem-session-array-becomes-empty/#findComment-195454 Share on other sites More sharing options...
Orio Posted February 27, 2007 Share Posted February 27, 2007 Yeah, I was just making sure. Try replacing all of these: $_SESSION['eventID[ .$arrayElement]'] With these: $_SESSION['eventID'.$arrayElement] Orio. Link to comment https://forums.phpfreaks.com/topic/40392-solved-array-problem-session-array-becomes-empty/#findComment-195456 Share on other sites More sharing options...
Caislean Posted February 28, 2007 Author Share Posted February 28, 2007 That work perfectly. Thanks, Orio! Link to comment https://forums.phpfreaks.com/topic/40392-solved-array-problem-session-array-becomes-empty/#findComment-196271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.