Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to update database from nestedsortable to hierachical
    text
    copied!<p>I want to know how to update my database based on this type of array:</p> <pre><code>Array ( [0] =&gt; Array ( [id] =&gt; 58 [children] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 62 [children] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 61 ) ) ) ) ) [1] =&gt; Array ( [id] =&gt; 60 [children] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 63 ) ) ) [2] =&gt; Array ( [id] =&gt; 0 [children] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 59 ) ) ) ) </code></pre> <p>I tried different methods but it's not working as it should.</p> <p>Here's my function that saved the new order of my list, I use <code>nestedSortable('toHierarchy')</code></p> <pre><code>function order() { $list = $_POST['list']; foreach ($list as $key =&gt; $value) { if(is_array($value['children'])) { $i=1; foreach($value['children'] as $k=&gt;$v) { $this-&gt;section-&gt;edit(array('order' =&gt; $i, 'parent_id'=&gt;$value['id']), "WHERE `id`=" . $v['id']); echo 'parent '.$value['id'].'child-&gt;'.$v['id'].' order-&gt;'.$i.'&lt;br/&gt;'; $i++; } } else { $this-&gt;section-&gt;edit(array('order' =&gt; $key, 'parent_id'=&gt;0), "WHERE `id`=" . $value['id']); } } } </code></pre> <p>But it's not working for list with more than 2 levels.</p> <p>this is the js i'm using</p> <pre><code>$('ol.sortable').nestedSortable({ update : function () { var orderNew = $(this).nestedSortable('serialize', {startDepthCount: 0}); //alert(orderNew); $.ajax({ type: 'post', url: '&lt;?php echo (APP_URL); ?&gt;projects/&lt;?php echo $project_id; ?&gt;/sections/order_list', data: {list:orderNew} }); }, disableNesting: 'no-nest', forcePlaceholderSize: true, handle: 'div', helper: 'clone', items: 'li', maxLevels: 4, opacity: .6, placeholder: 'placeholder', revert: 250, tabSize: 25, tolerance: 'move', toleranceElement: '&gt; div' }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload