Forum Moderators: coopster
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
$_SESSION['stdSelected[$i]']
You would use this:
$_SESSION['stdSelected'][$i]