Re: Multiple Select Stuff
| From: | Bryan Fritchie | Date: | Sun, 06 Aug 2000 05:49:49 +0000 |
| Subject: | Re: Multiple Select Stuff | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-10302@lists.php.net to get a copy of this message | ||
That's a good though. I've always done nested for loops to do multiple
select boxes.
What about doing the same thing, but using the in_array function, to do the
same thing?
if (in_array('def', $array))
I've never used it, but looks like it would work. If it does, let me know,
cause I'm gonna start using it. :)
----- Original Message -----
From: "John Coggeshall" <someone@internetaddress.com>
To: "Joe Conway" <jconway2@home.com>
Cc: "php general" <php-general@lists.php.net>
Sent: Saturday, August 05, 2000 12:44 AM
Subject: RE: [PHP] Multiple Select Stuff
>
> You've got the right idea, and yes the select box is multiple-select. I
was
> just hoping there was a way to format the array so that, at LEAST, it was
> the KEY that was set in the array (and not the value) so that....
>
> instead of (for a multiple-select box):
>
> array(0=>"abc",
> 1=>"def");
>
> It would be:
>
> array("def"=>1,
> "abc"=>0);
>
> That way, I could save myself the trouble of trying to loop through the
> array looking for a match, instead I could just do a
> if(isset($array['myselect']['def']))
>
> Do you see what I mean?
>
> John
>
>
>
> > -----Original Message-----
> > From: Joe Conway [mailto:jconway2@home.com]
> > Sent: Sunday, August 06, 2000 1:17 AM
> > To: John Coggeshall
> > Cc: php general
> > Subject: Re: [PHP] Multiple Select Stuff
> >
> >
> > >> Okay, Say you having something like...
> > >>
> > >> <SELECT NAME="myselect[]" MULTIPLE>
> > >> <OPTION VALUE="abc">ABC</OPTION>
> > >> <OPTION VALUE="def">DEF</OPTION>
> > >> <OPTION VALUE="ghi">GHI</OPTION>
> > >> </SELECT>
> > >>
> > >> My problem is I'd like PHP to select certain options in the
> > list that the
> > >> user selected perviously. Does that make sense?
> > >>
> > >> Any suggestions?
> >
> >
> > I'm not sure if I understand what you're trying to accomplish,
> > but I'll take a stab at it. Your last statement makes it sound
> > like you want the previously selected value in a list of values
> > to be pre-selected. In that case, here's an example. It assumes
> > that the last selected value of $prod_sn is already known.
> >
> > print("<TD width=\"25%\"><SELECT NAME=\"prod_sn\"
> > style=\"width:95%\">\n");
> > $sql = "select distinct product_sn from c_hdr";
> > $rs = pg_exec($conn,$sql);
> > $numrecs = pg_numrows($rs);
> > for ($row = 0; $row < $numrecs; $row++) {
> > if (pg_result($rs,$row,0) != $prod_sn) {
> > print("<OPTION VALUE=\"" . pg_result($rs,$row,0) .
> > "\">");
> > } else {
> > print("<OPTION VALUE=\"" . pg_result($rs,$row,0) . "\"
> > SELECTED>");
> > }
> > print(pg_result($rs,$row,0) . "</OPTION>\n");
> > };
> > if (pg_numrows($rs) == 0) {
> > print("<OPTION>No matches found</OPTION>\n");
> > }
> > pg_freeresult($rs);
> > print("</SELECT></TD>\n");
> >
> >
> > I think if you add MULTIPLE to the <SELECT> tag (i.e. <SELECT
> > NAME="prod_sn" style="width:95%" MULTIPLE>) and if $prod_sn were
> > an array of previously selected values, you could modify the
> > above to acheive your desired result (i.e. loop through all of
> > the $prod_sn[] values when testing for a match).
> >
> > Hope this helps,
> >
> > Joe
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>