Displaying Database Data Within the Flow the Site
Drupal splits functionality (modules) and layout (themes) to keep everything maintainable.

Instead of echoing everything, you need to pass your output from your module to the theme.

First step is making a menu item. This will give you an url to work with: https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_menu/7

Basic example:

function pathfindertool_hook_menu() {
    $items['pathfinderurl'] = array(
      'page callback' =&gt; 'pathfindertool_page',
    );
    return $items;
}


The page callback point to a function that contains your logic. You can choose the function name, but it's advised to start with your module name.

function pathfindertool_page() {
  $output = '';
  drupal_add_js('document.getelementbyId("pathfinder-primary-form").innerHTML = "', 'inline');

  $title = $row['title'];

  drupal_add_js('document.getelementbyId("pathfinder-primary-form").innerHTML = "', 'inline');

  // Do whatever you did to fill result.
  if ($result) {
    while ($row = $result-&gt;fetchAssoc()) {
      $title = $row['title'];
      $output.= '&lt;p&gt;' . $title. '&lt;/p&gt;';

    }
  }
  return $output;
}


Returning the output will make sure it will show in the right place. Never use echo or print, it will show up at the top.

You must always return something, even an empty string is ok, return NULL will result in a WSOD. That's why I always start my function with $output = '';