Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.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
Javascript Jquery Sortable:更新数据库的未定义索引_Javascript_Php_Jquery_Jquery Ui Sortable - Fatal编程技术网

Javascript Jquery Sortable:更新数据库的未定义索引

Javascript Jquery Sortable:更新数据库的未定义索引,javascript,php,jquery,jquery-ui-sortable,Javascript,Php,Jquery,Jquery Ui Sortable,我目前正在做一个学校项目,计划在2016年1月底完成。我对jQuery还是新手,因此,我真的需要一些帮助来解决我的这个问题。 关于,我尝试了排序表,但是现在的问题是序列化它以更新数据库 <script type="text/javascript"> $(document).ready(function () { $("#sortable").sortable({ opacity: 0.6,

我目前正在做一个学校项目,计划在2016年1月底完成。我对jQuery还是新手,因此,我真的需要一些帮助来解决我的这个问题。 关于,我尝试了排序表,但是现在的问题是序列化它以更新数据库

<script type="text/javascript">
        $(document).ready(function () {

            $("#sortable").sortable({
                opacity: 0.6,
                cursor: 'move',
                update: function () {
                    $('#changeMessage').html('Changes not saved');
                    $('#changeMessage').css("color", "red");
                }

            });

        });

        function saveDisplayOrder()
        {
            var order = $("#sortable").sortable("serialize");
            $('#changeMessage').html('Saving changes..');
            $.post("update_displayorder.php", order, function (theResponse) {
                $("#changeMessage").html(theResponse);
                $('#changeMessage').css("color", "green");
            });
        }

    </script>
在排序和单击按钮时,颜色和文字会相应变化。但是,它不会更新数据库中的顺序,因为ID是一个未定义的索引

注意:C:\xampp\htdocs\FYP\update\u displayorder.php中未定义的索引:ID


我想知道我到底做错了什么,因为我完全按照说明进行操作

您不需要更改数据库中的顺序,只需要在jquery/htmlthe教程中链接到排序
  • 。您的
    id
    位于
    上。您实际上是在排序
    s还是父级
    s?您的POST数据不在键值对中。因此,您不能作为
    $\u POST['ID']
    访问它。尝试
    $theID=file\u get\u contents('php://input');@Sean我正在整理
    。即使在使用
  • 之后,它仍然保持不变<代码>
    <?php
                        while ($item = mysqli_fetch_assoc($result)) {
                            ?>
                            <tr data-role="list-divider">
                                <td id="ID_<?php echo $item['idQuestions'] ?>" ><?php echo $item['Question'] ?>
                                </td>
                            </tr>
    <input type="button" onclick="return saveDisplayOrder()" value="Save Order" />
    
    $theID = $_POST['ID'];
    $counter = 1;
    
      foreach ($theID as $recordValue) {
      $query = "UPDATE questions SET displayOrder = '$counter'
              WHERE idQuestions = " . intval($recordValue);
      $result = mysqli_query($link, $query) or die(mysqli_error($link));
      $counter ++;
      }
    
    echo 'Changes saved';