Doing a foreach and ordering using $i++; for example but depending on a parent id in PHP
<p><strong>question updated:</strong></p>

<p>I've the next array, obtained from a nested sortable tree. The <code>$key</code> means the id of a PAGE and the <code>$value</code> it's the parent id. In my MySQL table I've to modify the <code>parent_id</code> of every page (when updating) and store the ORDER of a PAGE depending of the parent ID.</p>

<p>In the next example I've 3 ids with <code>parent_id</code> = 1: 5, 2 and 3. I've to update on MySQL 5,2 and 3 saving like:</p>

<pre><code>UPDATE pages SET parent_id=1,order=0 WHERE id=5
UPDATE pages SET parent_id=1,order=1 WHERE id=2
UPDATE pages SET parent_id=1,order=2 WHERE id=3

Array
(
    [1] =&gt; 0
    [5] =&gt; 1
    [2] =&gt; 1
    [3] =&gt; 1
    [4] =&gt; 3
    [6] =&gt; 3
)
</code></pre>

<p>How I can handle this with PHP? I'll do a <code>foreach</code> for every page id and send a MySQL update on each of loop for the <code>foreach</code>?</p>

<p>Thank you in advance!</p>
