home.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
<?php //layount $query = " SELECT * FROM app_layout WHERE userid=".$_SESSION['authenticated_user_id']." ORDER BY layoutsort ASC "; $res_layout = $mysqli->query($query); require_once("include/home.layout.php"); ?> <style> /* Sortable ******************/ /* #sortable .divcontent { margin:0; border: 1px solid #F5F5F5; } */ #sortable div span,.div-move { cursor: move; } @media (min-width: 768px) { #sortable .col-md-6{ overflow-y:auto;height:350px; border:dashed #eeeeee; border-width:1px; } } #divsaved { position:absolute;left: 40%;top:30%;z-index: 1; display:none; } </style> <div class="alert alert-success" id="divsaved" role="alert">Layout Saved</div> <div class="row" id="sortable"> <?php $cy=0; while($rowlayout = $res_layout->fetch_array()){ $cy++; $fncname = "get_".$rowlayout['layoutname']; if (function_exists($fncname)){ ?> <div class="col-md-6" id="<?php echo $rowlayout['layoutid']; ?>"> <?php $fncname(); ?> </div> <?php }} ?> </div> <script type="text/javascript"> /* * Author : Ali Aboussebaba * Email : bewebdeveloper@gmail.com * Website : http://www.bewebdeveloper.com * Subject : Dynamic Drag and Drop with jQuery and PHP */ $(function() { $('#sortable').sortable({ opacity: 0.7, handle: '.page-header', update: function(event, ui) { var list_sortable = $(this).sortable('toArray').toString(); // change order in the database using Ajax $.ajax({ url: 'blank.php?module=index&action=setLayout', type: 'POST', data: {list_order:list_sortable}, success: function(data) { //finished $('#divsaved').fadeIn(1000); $('#divsaved').fadeOut(1000); } }); } }); // fin sortable }); </script> |
setLayout.php
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php // get the list of items id separated by cama (,) $list_order = input_post('list_order'); // convert the string list to an array $list = explode(',' , $list_order); $i = 1 ; foreach($list as $id) { $query = " UPDATE app_layout SET layoutsort=".$i." WHERE userid=".$_SESSION['authenticated_user_id']." AND layoutid=".$id; $res_update = $mysqli->query($query); $i++ ; } ?> |
ดูเพิ่มเติม http://www.bewebdeveloper.com/tutorial-about-dynamic-drag-and-drop-with-jquery-and-php