I have form with a multiple selection, which has MySQL table column names as dynamic options.
<select id="rankRights" size="10" class="form-control" name="rights[]" multiple>
<?php
$sql = $pdo->query("SELECT * FROM ranks");
$rights = $sql->fetch(PDO::FETCH_ASSOC);
foreach($rights as $key => $value) {
if($key != 'Name' || $key != 'Id') {
echo "<option value=\"".$key."\"";
if($result[$key] == '1') {
echo " selected";
}
echo "> " . $key . "</option>";
}
}
?>
</select>
And in table there is user rights as columns and value 1 or 0 (means true or false, example below). There can be any number of columns.
.--------------------------------------------------------------------------------. | Id | Name | ADMIN | ADMIN_EDITUSER | ADMIN_DELETEUSER | etc | '--------------------------------------------------------------------------------' | 1 | Admin | 1 | 1 | 1 | ... | | 2 | Default | 0 | 0 | 0 | ... | '--------------------------------------------------------------------------------'
What I want to do is update the values to 1 if user has selected column name in multiple selection and vice versa. How can I post those to the PDO query..
EDIT: So, if I submit the form (for example selected ADMIN
and ADMIN_EDITUSER
from multiple selection), I'll get POST params like rights[]=ADMIN
and rights[]=ADMIN_EDITUSER
-> in that case I want to update values of columns ADMIN
and ADMIN_EDITUSER
to 1, and values of all other columns (options not selected) to 0.
I have read following questions and thinking something, but I don't even now know how to do this.