Add a link to unflag all node
Create a custom module that implements hook_menu().  Use that to create a path and a custom callback function that will run your query.  Something like:

/**
 * Implementation of hook_menu()
 */
function MYMODULE_menu() {
  $items = array();

  $items['flags/remove/%user'] = array(
    'page callback' =&gt; 'MYMODULE_remove_flags',
    'page arguments' =&gt; array(2),
    'access callback' =&gt; 'MYMODULE_check_access',
    'access arguments' =&gt; array(2),
    'type' =&gt; MENU_CALLBACK,
  );

  return $items;
}

// Adding custom functions, etc


To get started on creating a custom module, the Module developer's guide