function menu_distribute($pid) { $result_brothers = db_query('SELECT * FROM {menu} WHERE pid = \'%d\' ORDER BY weight, title asc', $pid); if ( db_num_rows($result_brothers) > 19 ) { drupal_set_message("Too many children for clean distribution of weights, movement failed.", "error"); return false; } else if ( db_num_rows($result_brothers) < 2 ) { drupal_set_message("No brothers and sisters, no movement possible.", "error"); return false; } else { $row_count = db_num_rows($result_brothers); $weight = - round($row_count/2); while ( $current_row = db_fetch_object($result_brothers) ) { drupal_set_message($current_row->title. ": $weight."); db_query('UPDATE {menu} SET weight = \'%d\' WHERE mid = \'%d\'', $weight, $current_row->mid); $weight++; } drupal_set_message("Menu is being rebuilt."); menu_rebuild(); return true; } }