dpd7195 2017-03-22 06:54
浏览 21

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

My code is writing from an array "Value1,Value2,Value3" to the table:

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

I am using a bootstrap Tag field and when I remove Value2, the array changes to "Value1,Value3" but does not delete the Value2 in the database table.

How do I check and remove Value2?

This is my current code:

$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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度