At 11:08 PM 11/25/2013, John Taylor-Johnston wrote:
I have a SET field in MYSQL.
'1. Type One','2. Type Two','3. Type Three'
The user can multi-select
<select name="DPRtype[]" multiple>
<option value="1. Type One">
<option value="2. Type Two">
<option value="3. Type Three">
</select>
I just dont know how to express $_POST[DPRtype] to be able to build
the $SQL to express the separate possibilities.
$sql = "UPDATE `taylorjo`.`CRTP_CGA`
SET
`DPRtype` = '$_POST[DPRtype]'
";
If I use a foreach like this, it will be very clunky. And I'll have
an extra comma at the end. What is a cleaner way?
$MyString = express_value_select ($_POST['DPRtype'],"1. Type One");
$MyString .= express_value_select ($_POST['DPRtype'],"2. Type Two");
$MyString .= express_value_select ($_POST['DPRtype'],"3. Type Three");
function express_value_select($tofilter,$tofind) {
foreach($tofilter as $value){
if ($value == $tofind) echo $tofind.",";
}
}
You don't want to use "echo" in a function, you want to return the
value. Store the values returned in a temporary array, then implode
the array to get the comma separated string
<?php
function express_value_select($tofilter,$tofind) {
foreach($tofilter as $value){
if ($value == $tofind) return $tofind;
}
}
$tmp = array();
$tmp[] = express_value_select ($_POST['DPRtype'],"1. Type One");
$tmp[] = express_value_select ($_POST['DPRtype'],"2. Type Two");
$tmp[] = express_value_select ($_POST['DPRtype'],"3. Type Three");
$MyString = implode(", ",$tmp);
?>
Ken
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php