保存拖放位置在轨道上

问题描述:

我想拖放列表中的位置将保存在数据库.......如果我刷新该页面的位置将不会改变... ...保存拖放位置在轨道上

在下面我加了这一概念,但在PHP代码中,我要如何在轨做......请帮我..........

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>jQuery Sortable With AJAX &amp; MYSQL</title> 
<script type="text/javascript" src="jquery-1.2.6.min.js"></script> 
<script type="text/javascript" src="jquery-ui-personalized-1.6rc4.min.js"></script> 
<link rel='stylesheet' href='styles.css' type='text/css' media='all' /> 
<script type="text/javascript"> 
    // When the document is ready set up our sortable with it's inherant function(s) 
    $(document).ready(function() { 
    $("#test-list").sortable({ 
     handle : '.handle', 
     update : function() { 
     var order = $('#test-list').sortable('serialize'); 
     $("#info").load("process-sortable.php?"+order); 
     } 
    }); 
}); 
</script> 
</head> 

<body> 
<pre> 

<div id="info">Waiting for update</div> 
</pre> 
<ul id="test-list"> 
    <li id="listItem_1">< alt="move" width="16" height="16" class="handle" /><strong>Item 1 </strong>with a link to <a href="http://www.google.co.uk/" rel="nofollow">Google</a></li> 
    <li id="listItem_2"><i alt="move" width="16" height="16" class="handle" /><strong>Item 2</strong></li> 
    <li id="listItem_3"><i" alt="move" width="16" height="16" class="handle" /><strong>Item 3</strong></li> 
    <li id="listItem_4">< alt="move" width="16" height="16" class="handle" /><strong>Item 4</strong></li> 

</ul> 
</body> 
</html> 

在php .........

<?php 
/* This is where you would inject your sql into the database 
    but we're just going to format it and send it back 
*/ 

foreach ($_GET['listItem'] as $position => $item) : 
    $sql[] = "UPDATE `table` SET `position` = $position WHERE `id` = $item"; 
endforeach; 

print_r ($sql); 
?> 
+0

什么是您的Rails应用程序看起来像那么远? – Wukerplank 2011-03-08 09:02:27

+0

感谢您的链接:) – Awea 2011-09-21 08:55:35

+0

awesomeful.net链接似乎是404. – y0mbo 2012-09-13 00:01:04

+0

你可能想看看这个,而不是:http://webtempest.com/sortable-list-in-ruby-on-rails-3-almost -unobtrusive-的jQuery / – tjeden 2012-09-14 09:16:56