On Sat, 25 May 2002, Victor Spång Arthursson wrote:
> I know it's possible to use arrays in combination with forms, but I need
> some advice about where to find some information/tutorial concerning how
> to use arrays together with "multi-select-tags"...

Have a play with this little program - it should demonstrate all of the
things you'd want to do with getting data in and out of mult selects. If
it doesn't work, you may have an older version of PHP - in that case,
change "$_REQUEST" to "$HTTP_POST_VARS" and "$_SERVER['PHP_SELF']" to


  $choices = array(1 => 'dog', 2 => 'cat', 3 => 'mouse', 4 => 'frog');

  if (is_array($_REQUEST['animals']))
    print '<p>You chose:</p><ul>';
    foreach ($_REQUEST['animals'] as $animal_id)      
      print "<li>{$choices[$animal_id]}</li>";
    print '</ul><hr>';

  ?><form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
  <select multiple name="animals[]"><?

  foreach ($choices as $id => $name)
    print '<option '
      . (in_array($id, $_REQUEST['animals']) ? 'selected ' : '')     
      . "value='$id'>$name</option>";

  ?></select><input type="submit"></form>


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to