更新多个选择框

时间:2015-08-03 08:02:34

标签: php database forms select

我有这样的代码:

<?php
    if($_GET["id"]){
        $rezIzmjena = mysqli_query($kon, "SELECT * FROM shops WHERE id=". $_GET["id"] ." LIMIT 1");
        $redIzmjena = mysqli_fetch_assoc($rezIzmjena);
        $fotoTxt = "Nieuwe logo :";
        $btnTxt = "Veranderen";
    }else{
        $fotoTxt = "Kies logo :";
        $btnTxt = "Toevoegen";
    }
 ?>

<div class="col-xs-12 col-sm-5">
    <select class="form-control" name="slcRegio[]" multiple="multiple">
    <?php 
            $rez = mysqli_query($kon, "SELECT * FROM regios");
            echo "<option selected disabled>Kies een regio</option>";
            while($red = mysqli_fetch_assoc($rez)){
                $rez1 = mysqli_query($kon, "SELECT regios.id, shop_regio_tt.regio_id, shop_regio_tt.shop_id FROM regios INNER JOIN shop_regio_tt ON regios.id = shop_regio_tt.regio_id");
                while($red1 = mysqli_fetch_assoc($rez1)){
                   if($red1["shop_regio_tt.shop_id"] == $redIzmjena["id"]){
                        $selected = "selected"; 
                    }else{
                        $selected = ""; 
                    }
                }
                echo "<option value=\"". $red["id"] ."\" ". $selected .">". $red["naam"] ."</option>";

            }
    ?>
 </select><br />
  </div>

在我的数据库中,我有商店表(id,naam,...),regios表(id,naam)和shop_regio_tt(id,shop_id,regio_id)。

当我想要更新项目时,我想要查看已选择的项目。但是我的代码没有选择。

我在这里获取结果

 foreach ($_POST["slcRegio"] as $regio_id){

        mysqli_query($kon, "INSERT INTO shop_regio_tt VALUES(NULL,". $_POST["izmjena"] .",". $regio_id .")");


                    }

如果已发送隐藏字段,如何更新shop_regio_tt?

提前致谢。

1 个答案:

答案 0 :(得分:0)

是的,但在您的代码中有

  

if($ red1 [“shop_regio_tt.shop_id”] == $ redIzmjena [“id”])

我没有找到变量$ redIzmjena。

我认为它应该是$ red ['id']