RE: [PHP] Multiple Select Stuff

From: Date: Sat, 05 Aug 2000 05:52:30 +0000
Subject: RE: [PHP] Multiple Select Stuff
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10303@lists.php.net to get a copy of this message
Learn a new trick every day :) Thanks Rasmus John > -----Original Message----- > From: Rasmus Lerdorf [mailto:rasmus@linuxcare.com] > Sent: Sunday, August 06, 2000 1:48 AM > To: John Coggeshall > Cc: Joe Conway; php general > Subject: RE: [PHP] Multiple Select Stuff > > > Just flip the array then (array_flip) > > -Rasmus > > On Sat, 5 Aug 2000, John Coggeshall wrote: > > > > > 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 > > > > > > > > > > > > >

« previous php.general (#10303) next »