title: Move node in a nested set
body: <p>I'm trying to use the answer here : <a href="https://stackoverflow.com/questions/889527/mysql-move-node-in-nested-set">Move node in nested set</a></p>
  
  <p>To move a node in a mysql nested set db it appears to work ok except the moving node is set to a negative value and is never changed to the new lft &amp; rgt values.  It appears as if Step 4 is not doing anything at all.  I've changed the script to match my structure and removed the update parentID in step 4 because I don't store the parentID in my structure.</p>
  
  <p>Can someone tell me why this is not working?  here is my code :</p>
  
  <pre><code>// id of moving node 
  $iItemId = 13;
  
  // left position of moving node
  $iItemPosLeft = 19;
  
  // right position of moving node
  $iItemPosRight = 20;
  
  // id of new parent node (where moving node should be moved)
  $iParentId = 8;
  
  // right position of new parent node (where moving node should be moved)
  $iParentPosRight = 15;
  
  // 'size' of moving node (including all its sub-nodes)
  $iSize = $iItemPosRight - $iItemPosLeft + 1;
  
  $sql = array(
  
  // step 1: temporarily "remove" moving node
  
  'UPDATE `RJF_storeNestedCategory`
  SET `lft` = 0-(`lft`), `rgt` = 0-(`rgt`)
  WHERE `lft` &gt;= "'.$iItemPosLeft.'" AND `rgt` &lt;= "'.$iItemPosRight.'"',
  
  // step 2: decrease left and/or right position values of currently 'lower' items (and     parents)
  
  'UPDATE `RJF_storeNestedCategory`
  SET `lft` = `lft` - '.$iSize.'
  WHERE `lft` &gt; "'.$iItemPosRight.'"',
  'UPDATE `RJF_storeNestedCategory`
  SET `rgt` = `rgt` - '.$iSize.'
  WHERE `rgt` &gt; "'.$iItemPosRight.'"',
  
  // step 3: increase left and/or right position values of future 'lower' items (and parents)
  
  'UPDATE `RJF_storeNestedCategory`
  SET `lft` = `lft` + '.$iSize.'
  WHERE `lft` &gt;= "'.($iParentPosRight &gt; $iItemPosRight ? $iParentPosRight - $iSize : $iParentPosRight).'"',
  'UPDATE `RJF_storeNestedCategory`
  SET `rgt` = `rgt` + '.$iSize.'
  WHERE `rgt` &gt;= "'.($iParentPosRight &gt; $iItemPosRight ? $iParentPosRight - $iSize : $iParentPosRight).'"',
  
  // step 4: move node (ant it's subnodes) and update it's parent item id
  
  'UPDATE `RJF_storeNestedCategory`
  SET
      `lft` = 0-(`lft`)+'.($iParentPosRight &gt; $iItemPosRight ? $iParentPosRight - $iItemPosRight - 1 : $iParentPosRight - $iItemPosRight - 1 + $iSize).',
      `rgt` = 0-(`rgt`)+'.($iParentPosRight &gt; $iItemPosRight ? $iParentPosRight - $iItemPosRight - 1 : $iParentPosRight - $iItemPosRight - 1 + $iSize).'
  WHERE `lft` &lt;= "'.(0-$iItemPosLeft).'" AND i.`rgt` &gt;= "'.(0-$iItemPosRight).'"');
  
  
  foreach($sql as $sqlQuery){
    mysql_query($sqlQuery);
  }
  </code></pre>
  
  <p>I'm also interested if anyone knows how to use this to move a node left or right within its existing parent.</p>