如果值不在数组中,则从表中删除

时间:2017-03-22 06:54:15

标签: php mysql twitter-bootstrap

我的代码是从数组写入" Value1,Value2,Value3"到桌子:

+----+--------+
| ID |  Value |
+----+--------+
|  1 | Value1 |
+----+--------+
|  2 | Value2 |
+----+--------+
|  3 | Value3 |
+----+--------+

我正在使用引导标记字段,当我删除Value2时,数组变为" Value1,Value3"但不删除数据库表中的Value2。

如何查看和删除Value2?

这是我目前的代码:

$commaList = explode(', ', $support_membership);

            foreach ($commaList as $value) {
                $sql = "select * from groups where value like '$value' ";
                $rs = mysqli_query($database, $sql);
                if (!$rs) error_dlg(mysqli_error($database));

                if(mysqli_num_rows($rs) == 1){
                    //do nothing
                } else {
                    $sqlgroup = "insert into groups set ";
                    $sqlgroup .= "system='2', ";
                    $sqlgroup .= "value='$value' ";
                    mysqli_query($database, $sqlgroup);
                }

0 个答案:

没有答案