我是jquery的新手。
我一直在进行一项分配,以制作可排序的div并将其保存到数据库中。幸运的是我做到了。
我的问题是如何在点击save order
按钮时将该记录保存到数据库,而不是当我移动每个div时,应该隐藏保存按钮直到我移动任何div。
这就是它的外观 http://oi57.tinypic.com/fkxhc4.jpg
这是我移动任何div 时的方式
这是我的div
$item=array(
'<div class="ara001" id="item_0"><a href="job"><div><img src="image/Home/jobs.gif"/><div >Jobs</div></div></a></div>',
'<div class="ara001" id="item_1"><a href="job" ><div><img src="image/Home/friends.png"/><div >Friends</div></div></a></div>',
'<div class="ara001" id="item_2"><a href="job"><div><img src="image/Home/mails.png"/><div >Mails</div></div></a></div>',
'<div class="ara001" id="item_3"><a href="job"><div><img src="image/Home/libraries.png"/><div >Books</div></div></a></div>',
'<div class="ara001" id="item_4"><a href="job"><div><img src="image/Home/entertainments.png"/><div >Entertainments</div></div></a></div>',
'<div class="ara001" id="item_5"><a href="job"><div><img src="image/Home/musics.png"/><div >Musics</div></div></a></div>',
'<div class="ara001" id="item_6"><a href="job"><div><img src="image/Home/videos.png"/><div >Videos</div></div></a></div>',
'<div class="ara001" id="item_7"><a href="job"><div><img src="image/Home/markets.png"/><div >Markets</div></div></a></div>');
$result = mysqli_query($conn,"SELECT sort FROM users WHERE UserName = '$user_name'");
$order=mysqli_fetch_array($result);
$order=explode (',', $order[0]);
foreach($order as $key=>$value){
echo $item[$value];}
?>
</div>
这是可排序的脚本
<script>
$('#ara003').sortable({
update: function( event, ui ) {
var postData = $(this).sortable('serialize');
console.log(postData);
$.post('module/sort-save.php', {users: postData}, function(o){
console.log(o);
},'json');
}
});
</script>
最后这是sort-save.php文件
<?php
//------------------------------------------------------------
// RESTRICT ACCESS TO PAGE
//------------------------------------------------------------
require_once('../authentication/web.config.php');
require_once(ROOT_PATH.'global.php');
$auth_roles = array('member','user','owner','superadmin','etc.'); // << add roles here
//$premium_on = 1; $premium_access_levels = array('1','2');// << add premium access levels here
require_once(ROOT_PATH.'modules/authorization/auth.php');
require_once(ROOT_PATH.'user/modules/accordion/homepage_data.php');
$list = $_POST['users'];
$output=array();
$list=parse_str($list, $output);
$save=implode(',', $output['item']);
echo $save;
$conn->query("UPDATE users SET sort = '$save' WHERE UserName = '$user_name'");
?>