Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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 可排序数据和更新数据库问题_Javascript_Jquery_Jquery Ui Sortable - Fatal编程技术网

Javascript 可排序数据和更新数据库问题

Javascript 可排序数据和更新数据库问题,javascript,jquery,jquery-ui-sortable,Javascript,Jquery,Jquery Ui Sortable,我正在尝试让这个可排序的代码工作,我已经让它工作在上,就像在UI示例中一样,但是现在我使用的是s,这并没有真正的区别,但我认为它使事情变得复杂了一点 下面是我的可排序代码,附带了某种ajax更新: $(function() { $( ".heriyah" ).sortable({ connectWith: ".heriyah", handle: ".handle", cancel: ".add", update : func

我正在尝试让这个可排序的代码工作,我已经让它工作在
  • 上,就像在UI示例中一样,但是现在我使用的是
    s,这并没有真正的区别,但我认为它使事情变得复杂了一点

    下面是我的可排序代码,附带了某种ajax更新:

    $(function() {
        $( ".heriyah" ).sortable({
            connectWith: ".heriyah",
            handle: ".handle",
            cancel: ".add",
            update : function () {
            var order = $('.heriyah').sortable('serialize');
            $("#sortable").load("sortable.php?"+order);
            },
            receive: function(event, ui){
               alert('RECEIVE: ' + $(ui.sender).attr('id') + '=>' + $(this).attr('id') + ' ' + (ui.item.index()+1) + ' ' + $(ui.item).text());
            }
        });
    
        $( ".heriyah" ).disableSelection();
    });
    
    以下是sortable.php的内容:

    foreach ($_GET['sort'] as $position => $item) :
        $query = "UPDATE content SET `order` = $position WHERE `id` = $item";
        $result = mysql_query($query);
    endforeach;
    
    下面是如何设置我的页面:

    <div id="someID" class="heriyah">
        <div id="heriyah_sortable" class="sort_1">Content</div>
        <div id="heriyah_sortable" class="sort_2">Content</div>
        <div id="heriyah_sortable" class="sort_3">Content</div>
        <div id="heriyah_sortable" class="sort_4">Content</div>
    </div>
    
    其次,我对数据库的查询搞砸了。数据库需要在PHP元素周围加引号。有时数据库并不关心,但在某些情况下,如果没有引号,它会出错。在查询中,最好在列变量周围加上斜杠引号,然后在PHP变量周围加上单引号

    下面是我现在的查询:

      $query = "UPDATE content SET `order` = '$position' WHERE `id` = '$item'";
    
      $query = "UPDATE content SET `order` = '$position' WHERE `id` = '$item'";
    

    好的,在我的更新查询中,我的文件路径是错误的,而且更新函数本身也有问题。所以我现在把它改成这样:

    update : function (event, ui) {
            var order = $(this).sortable('serialize');
            $.post("admin/sortable.php?" + order);
    },
    
    update : function (event, ui) {
            var order = $(this).sortable('serialize');
            $.post("admin/sortable.php?" + order);
    },
    
    其次,我对数据库的查询搞砸了。数据库需要在PHP元素周围加引号。有时数据库并不关心,但在某些情况下,如果没有引号,它会出错。在查询中,最好在列变量周围加上斜杠引号,然后在PHP变量周围加上单引号

    下面是我现在的查询:

      $query = "UPDATE content SET `order` = '$position' WHERE `id` = '$item'";
    
      $query = "UPDATE content SET `order` = '$position' WHERE `id` = '$item'";
    

    如果您使用的是chrome,请按F12打开开发者工具,然后单击“网络”选项卡并尝试排序。每个排序操作都应该有一个网络活动,单击其中一个,然后在详细信息中查看您的post数据。如果没有任何post数据,sortable的序列化函数可能需要其他东西,或者它不工作。我在macbook上使用Firebug,但它没有显示任何内容,但我也只是更新了上面的代码!排序时是否有任何网络活动?完全没有活动。至少应该有东西!尝试.post、.get或.ajax而不是.load