Re: Multiple Select Stuff
| From: | Joe Conway | Date: | Sun, 06 Aug 2000 05:17:11 +0000 |
| Subject: | Re: Multiple Select Stuff | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-10299@lists.php.net to get a copy of this message | ||
>> 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