Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中选中onchange下拉列表显示复选框_Php_Jquery_Mysqli - Fatal编程技术网

在php中选中onchange下拉列表显示复选框

在php中选中onchange下拉列表显示复选框,php,jquery,mysqli,Php,Jquery,Mysqli,代码: 在这段代码中,我正在更新数据库中具有名称菜单的表。现在,我只想选中那些管理员id为1或2的复选框,这是通过查询更新的。如何解决此问题?请帮助 多谢各位 <script> $(document).ready(function(){ $(".menu").click(function(){ ids = $('.menu:checked').map(function() { return this.id;

代码:

在这段代码中,我正在更新数据库中具有名称菜单的表。现在,我只想选中那些管理员id为1或2的复选框,这是通过查询更新的。如何解决此问题?请帮助

多谢各位

<script>
  $(document).ready(function(){
    $(".menu").click(function(){
      ids = $('.menu:checked').map(function() {
              return this.id;
              }).get().join(',');
              console.log(ids);
        $("#ids").val(ids);      
    });
  });
</script>

<?php
if(isset($_POST['submit']))
{
  $adminid = $_POST['admin'];
  $menuids = explode(",", $_POST['ids']);
    foreach ($menuids as $idd) 
    {
      $sql = "update menu set admin_id = concat(admin_id,'$adminid',',') where id = '$idd'";
      $result = mysqli_query($link,$sql);
    }
    if($result == true)
      {
        $msg .= "<p style='color:green'>successfull</p>";
      }
      else
      {
        $msg .= "<p style='color:red'>error!</p>";
      }
}
?>

<form method="post">
  <select name="admin" id="admin">
    <option value="">---Select Admin---</option>
    <?php
      $sql = "select * from admin";
      $result = mysqli_query($link,$sql);
      while ($row = mysqli_fetch_array($result)) 
      {
    ?>
     <option value="<?php echo $row['id']; ?>"><?php echo $row['firstname']?></option> 
    <?php    
      }
    ?>
  </select>
  <table>
    <tr>
      <th>Share</th>
      <th>Menu Name</th>
    </tr>
    <?php
      $query = "select * from menu";
      $results = mysqli_query($link,$query);
      while ($fetch = mysqli_fetch_array($results)) 
      {
    ?>
        <tr>
          <td>
            <input type="checkbox" class="menu" id="<?php echo $fetch['id']; ?>" name="menuid" />
          </td>

          <td>
            <?php echo $fetch['menu_name']; ?>
          </td>
        </tr>
    <?php
      }
    ?>
  </table>
  <input type="text" name="ids" id="ids" value=""/>
  <input type="submit" name="submit" id="submit" />
</form>
   while ($fetch = mysqli_fetch_array($results)) 
  {
   ?>
    <tr>
      <td>
        <input type="checkbox" class="menu" value="<?php if($fetch['id']==1 or 
           $fetch['id']==2 ) { echo "checked";} else{} ?>" name="menuid" />
      </td>

      <td>
        <?php echo $fetch['menu_name']; ?>
      </td>
    </tr>
<?php
  }
?>