Help with a D7 database query and update
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.