php - Jquery sortable PDO update order -
i'm trying create sortable list updates pdo (php data objects). i've tried work out, although seems doesn't want update, , i'm unsure i've gone wrong. drag works fine, data seems work correct. doesn't update database.
main file jquery
<ul id="sortable"> <?php $sql = "select * ".$prefix."question enabled = 1 order sortby asc"; $stm = $dbh->prepare($sql); $stm->execute(); $u = $stm->fetchall(); $count = 0; foreach ($u $sup) { ?> <li id="item-<?php echo $sup['id']; ?>"><?php echo $sup['title']; ?></li> <?php } ?> </ul> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $('#sortable').sortable({ axis: 'y', update: function (event, ui) { var data = $(this).sortable('serialize'); // post server using $.post or $.ajax $.ajax({ data: data, type: 'post', url: 'order.php' }); } }); </script>
php file [order.php] (connection database fine , works correctly)
<?php ob_start(); session_start(); $admin = true; require "inc/config.php"; $i = 0; foreach ($_post['item'] $value) { // execute statement: // update [table] set [position] = $i [entityid] = $value $sql = $dbh->prepare("update ".$prefix."question set sortby='".$i."' id=1"); $sql->execute(); $i++; } ?>
if see problem is, i'd appreciate it.
was able fix this. issue how getting config.php database.
rest of code works.
Comments
Post a Comment