Aur1cles Posted August 6, 2012 Share Posted August 6, 2012 I have sortable panels, that users can drag around, that part works perfect. Inside those panels I have Jquery sortable links, that users can drag around the panels and I can't seem to get this to update database. This is the part where it get's the link paths from database and shows them: <ul style="list-style-type: none;" class="drag" id="order_<?php echo $row['id'];?>" name="<?php echo $link_sort_no;?>" title="<?php echo $title_id;?>"><li> <a href="<?php echo $link_adress; ?>"><?php echo $link_name;?></a><br/><br/> </li></ul> This is my Jquery and ajax: $(function () { $('.drag').sortable({ connectWith: '.drag', update : function(e, ui) { var title=$(this).attr('id'); var sort=$(this).attr('name'); //alert(id); //alert(sort); var ul = $(ui.item).closest('.drag'); var index = 0; var toPost = {}; ul.find('> li').each(function() { index++; $(this).find('.drag').val(index); toPost[$(this).find('.drag').attr('name')] = index; }); $.ajax({ url : 'UpdateLink.php', data : toPost, type : 'POST', dataType : 'json', success : function(resp) { alert(resp); }, error : function() { alert('There was a problem'); } }); } }); }); And this is UpdateLink.php file, what should update the database: $order = $_POST['order']; for ($i = 0; $i < count($order); $i++) { mysql_query("UPDATE links SET link_sort_no=" . $i . " WHERE id=' ".$order[$i]."'") or die(mysql_error()); But I can't seem to get this to work, I' been trying everything. Maybe there's something wrong with ajax or jquery, I really don't know. I am just asking somebody to take a look at it and maybe helping a little bit I would appreciate it. I forgot to mention that users can drag links from one panel to another, so it needs to save two values to database title_id and link_sort_no. Quote Link to comment https://forums.phpfreaks.com/topic/266730-updating-database-with-phpajaxjquery/ Share on other sites More sharing options...
phpassassin Posted August 20, 2012 Share Posted August 20, 2012 try navigating your $_POST on your UpdateLink.php file, see if the variables array index "order" is present. and also i guess you gonna have this data formation: data : {order: toPost}, Quote Link to comment https://forums.phpfreaks.com/topic/266730-updating-database-with-phpajaxjquery/#findComment-1370757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.