Reputation: 41
I currently edit an open source program and have a question: the php code is actually like this:
print "<select multiple name=\"appliesto[]\" size=\"5\">";
foreach ($products as $k => $v) {
$pid = $k;
$group = $v['group'];
$prodname = $v['name'];
print "<option value=\"$pid\">$group - $prodname</option>";
}
print "</select>
Is it possible to get 2 values with each selected option? Because I need to save $pid and $prodname in 2 different columns on a mysql table.
Thanks!
Upvotes: 4
Views: 123
Reputation: 3530
You can put at the value attribute some delimiter to the values something like this:
print "<select multiple name=\"appliesto[]\" size=\"5\">";
foreach ($products as $k => $v) {
$pid = $k;
$group = $v['group'];
$prodname = $v['name'];
print "<option value=\"$pid|$prodname\">$group - $prodname</option>";
}
print "</select>
when you post the data you can explode the data by the delimiter in this case |
in order to get the 2 values.
list($pid,$prodname) = explode("|", $inputSelect, 2);
Upvotes: 3