Re: [PHP] Drop Down Box Question

2002-07-23 Thread Jason Stechschulte

On Sun, Jul 21, 2002 at 11:43:25AM -0400, WANDA HANSEN wrote:
 Is there a way to handle data gathered from a drop down menu that
 allows multiple selections using PHP?

Yes.  The way I normally do this is to use HTML that looks something
like:

select multiple='multiple' name='test[]'
option value='1'Red/option
option value='2'Green/option
option value='3'Blue/option
/select

Now in your PHP program, you can access them all with something like:

?php
foreach($_POST['test'] as $test) {
   echo You selected $testbr /\n;
}
?

-- 
Jason Stechschulte
[EMAIL PROTECTED]
http://www.ypisco.com
--
History books which contain no lies are extremely dull.

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




Re: [PHP] Drop Down Box Question

2002-07-21 Thread Richard Lynch

 Hello,
 Is there a way to handle data gathered from a drop down menu that
allows
 multiple selections using PHP?

Of course. Name your select box as an array, and include the 'multiple'
keyword.

select name='something[]' multiple

Then you'll have an array on your processing page that holds all of the
values that were selected. $_POST['something'][]. Note that it starts at
zero. 

You can use count($_POST['something']) to see how many were selected,
etc...

If you need specific IDs or something from the OPTIONs presented, other than
the text between the tags, you can even use the VALUE= attribute to pass
around data so that $_POST['something'] doesn't just start at 0 and count
up:

?php
  while (list($id, $name) = each($ineeddatacaptain)){
echo $id: $nameBR\n;
  }
?
SELECT NAME=ineeddatacaptain[] MULTIPLE SIZE=5
  OPTION VALUE=1Captain Kirk/OPTION
  OPTION VALUE=2Spock/OPTION
  OPTION VALUE=3McCoy/OPTION
  OPTION VALUE=4Scotty/OPTION
  OPTION VALUE=5Sulu/OPTION
  OPTION VALUE=6Uhura/OPTION
  OPTION VALUE=7Chekov/OPTION
/SELECT

If you click on Spock, instead of just 0, Spock, you'll get 2, Spock -- You
get his ID number as well as his name.

This is extremely convenient.  And you sure can't do that in ASP easily :-)

-- 
Like Music?  http://l-i-e.com/artists.htm

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




RE: [PHP] Drop Down Box Question

2002-07-21 Thread John Holmes

 -Original Message-
 From: Richard Lynch [mailto:[EMAIL PROTECTED]]
 Sent: Sunday, July 21, 2002 5:06 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Drop Down Box Question
 
  Hello,
  Is there a way to handle data gathered from a drop down menu that
 allows
  multiple selections using PHP?
 
 Of course. Name your select box as an array, and include the
'multiple'
 keyword.
 
 select name='something[]' multiple
 
 Then you'll have an array on your processing page that holds all of
the
 values that were selected. $_POST['something'][]. Note that it starts
at
 zero.
 
 You can use count($_POST['something']) to see how many were selected,
 etc...
 
 If you need specific IDs or something from the OPTIONs presented,
other
 than
 the text between the tags, you can even use the VALUE= attribute to
pass
 around data so that $_POST['something'] doesn't just start at 0 and
count
 up:
 
 ?php
   while (list($id, $name) = each($ineeddatacaptain)){
 echo $id: $nameBR\n;
   }
 ?
 SELECT NAME=ineeddatacaptain[] MULTIPLE SIZE=5
   OPTION VALUE=1Captain Kirk/OPTION
   OPTION VALUE=2Spock/OPTION
   OPTION VALUE=3McCoy/OPTION
   OPTION VALUE=4Scotty/OPTION
   OPTION VALUE=5Sulu/OPTION
   OPTION VALUE=6Uhura/OPTION
   OPTION VALUE=7Chekov/OPTION
 /SELECT
 
 If you click on Spock, instead of just 0, Spock, you'll get 2, Spock
--
 You
 get his ID number as well as his name.

That's confusing. There's no way to get Spock from the code. You only
get the number in the value attribute. If the user were to choose Spock
and McCoy, then you'd have:

$_POST['ineeddatacaptain'][0] -- 2
$_POST['ineeddatacaptain'][1] -- 4

It's up to the programmer to associate 2 with Spock, and 4 with McCoy.

---John Holmes...


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




RE: [PHP] drop down box

2002-03-20 Thread Demitrious S. Kelly

This is actually a small excerpt from a program I've written in the
past... hope it helps...

function show_downtime_form() {
global $conf_file;
global $filter;
$data=file($conf_file);
foreach ( $data as $line ) {
$bang=explode(':', $line);
$idents[]=$bang[0];
}
$idents=array_unique($idents);
echo 'div align=centerhr width=300';
echo 'form name=inputform action=reports.php
method=post';
echo 'Match Idents To:br';
echo 'input type=text name=filter value='.$filter.'';
echo 'br - OR Select - br';
echo 'select name=temp onchange=doEcho()';
echo 'option selected--From Current Idents--';
foreach($idents as $ident) {
echo 'option value='.$ident.''.$ident;
}
echo '/select';
echo 'br';
echo 'input type=submit value=search';
echo '/form';
echo '/div';
}

-Original Message-
From: ...::: M.E. Suliman :::... [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, March 20, 2002 9:57 AM
To: [EMAIL PROTECTED]
Subject: [PHP] drop down box

Hi

I need to get info from a specific field in a MySQL database to appear
in a
drop box as options. Has anyone any ideas on this.

Thanks

Mohamed





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



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