I am presently creating a custom WordPress admin page via functions.php. I would like this site to essentially retrieve information from the SQL database (unrelated to WordPress) and display it towards the customer. I'm able to do this fine, but when I stick the code with this during my functions.php, will that SQL code run virtually on every page request, regardless of what page? Here's my functions file virtually:

function mytheme_add_admin() {
add_menu_page('Members', 'Members', 'moderate_comments', 'members', 'mytheme_admin');
}

function mytheme_admin() {
?>
#all the code for my page here
<?php }

add_action('admin_menu', 'mytheme_add_admin');

The "#all of the code for my page here" could be HTML and items of PHP to seize SQL data. It is possible to method to get this to only happen when viewing that admin page?

This can operate a query on every page load unless of course you give a condition either inside the function itself or (ideally) round the add_action() call. You will find a number of ways of getting it run only on one page, however the two simplest ways are most likely to make use of wordpress' built-in global variable 'pagenow' in order to use among the $_SERVER variables to complete exactly the same ($_SERVER['REQUEST_URI'] for example)

if (in_array($GLOBALS['pagenow'], array(pages this should show up on))){
   add_action('admin_menu', 'mytheme_add_admin');
}

or

if (in_array($_SERVER['REQUEST_URI'], array(pages this should show up on with path from root))){
    add_action('admin_menu', 'mytheme_add_admin');
}