Forum Moderators: coopster

Message Too Old, No Replies

Accessing an array WITHIN a $ Session var

         

neophyte

4:03 am on Nov 10, 2006 (gmt 0)

10+ Year Member



Hello All -

I've got a "multiple-choice" select list that's generated by an array ($stdAvailable) of room numbers (i.e. A, B, C, D, etc)

Once the list is generated, the user can choose one or more numbers from the list. When submit is pressed, the post values are sent to a session VAR as an array. So far so good.

Problem I'm having is that, when the select list is re-generated, I can't figure out how to access the session var array to compare against the $stdAvailable array to show which items have been previous chosen.

Code Snippet here:

*******************************************************

echo '<select name="stdSelected[]" multiple>';

for ($i = 0; $i < count($stdAvailable); $i++)
{
echo '<option value="' , $stdAvailable[$i] , '"';
if (isset($_SESSION['stdSelected']) and $stdAvailable[$i] == $_SESSION['stdSelected[$i]'])
{
echo ' selected';
}
echo '>', $stdAvailable[$i] , '</option>';
}
echo '</select>';

******************************************************

I know its a syntax problem with the $_Session var -- $_SESSION['stdSelected[$i]'] -- because I'm always coming up with the undefined index warning stdSelected[$i].

What am I doing wrong? How does one pick through an array that's been put into a $_Session VAR?

Neophyte

eelixduppy

6:26 am on Nov 10, 2006 (gmt 0)



It's a multi-dimensional array, and you use it as such. Instead of this:

$_SESSION['stdSelected[$i]']

You would use this:


$_SESSION['stdSelected'][$i]

neophyte

9:22 am on Nov 10, 2006 (gmt 0)

10+ Year Member



eelixduppy -

Thanks, worked like a charm.

Neophyte