PHP jQuery-ui implements dragging floating layer sorting layout and saves the dragged floating layer position sorting result to the database instance.
First introduce the jQuery library and jquery-ui.min.js, then place a loading image during dragging, and drag multiple modules read from the database Layer.modules, and #orderlist are used to record the ordering value of the module.
<script type="text/javascript" src="jquery.js"></script> <script type='text/javascript' src='js/jquery-ui.min.js'></script> <div id="loader"></div> <div id="module_list"> <input type="hidden" id="orderlist" value="<?php echo $sort; ?>" /> <!--?php for ($i = 0; $i < $len; $i++) { ?--> <div class="modules" title="<?php echo $sort_arr[$i]; ?>"> <h3 class="m_title">Module: <!--?php echo $sort_arr[$i]; ?--></h3> <p> <!--?php echo $sort_arr[$i]; ?--></p> </div> <!--?php } ?--> <div class="cl"></div> </div>
Page js:
$(function() { $(".m_title").bind('mouseover', function() { $(this).css("cursor", "move") }); var $show = $("#loader"); //进度条 var $orderlist = $("#orderlist"); var $list = $("#module_list"); $list.sortable({ opacity: 0.6, revert: true, cursor: 'move', handle: '.m_title', update: function() { var new_order = []; $list.children(".modules").each(function() { new_order.push(this.title); }); var newid = new_order.join(','); var oldid = $orderlist.val(); $.ajax({ type: "post", url: "update.php", data: { id: newid, order: oldid }, //id:新的排列对应的ID,order:原排列顺序 beforeSend: function() { $show.html("<img src='images/load.gif' / alt="About PHP+jQuery-ui Drag floating layer to sort and save to database instance" > 正在更新"); }, success: function(msg) { $show.html(""); } }); } }); });
Drag and save to the database, the code in ajax.php:
$order = $_POST['order']; $itemid = trim($_POST['id']); if (!empty($itemid)) { if ($order != $itemid) { $query = mysql_query("update sortlist set sort='$itemid' where id=1"); if ($query) { echo $itemid; } else { echo "none"; } } }
Related recommendations:
PHP video tutorial:https://www.php.cn/course/list/29/type/2.html
The above is the detailed content of About PHP+jQuery-ui Drag floating layer to sort and save to database instance. For more information, please follow other related articles on the PHP Chinese website!