Help with a D7 database query and update I am not familiar with the Drupal 7 database API. I want to alphabetized a menu.
Can anyone help me write a database query to retrieve all the menu item links of a certain parent (plid = 228) and order ascending by title? Within that result set, can anyone help me write a database update method to update each menu item's weight sequentially (counter starts at 0 and increments)?
Something like this should work, but I have not tested this code. Please comment on this if you have questions.

$result = db_select('menu_links', 'ml') 
  -&gt;fields('ml', 'mlid')
  -&gt;condition('ml.plid', $plid, '=')
  -&gt;orderBy('ml.link_title')
  -&gt;execute();

$i=0;
foreach ($result as $row) {
  db_update('menu_links')
    -&gt;fields(array('weight' =&gt; $i))
    -&gt;condition('mlid', $row-&gt;mlid)
    -&gt;execute();
  $i++;
}


At this point they would all be ordered by title, and you could print the menu wherever needed.