title: Reusing MYSQL queries on the same page
body: <p>I have a header.php and a footer.php file being included on the same page, they both return some of the same information. Specifically I use this query in each file.</p>
  
  <pre><code>&lt;?php   
      $q3 = "SELECT page_id, show_id, link_title FROM pages as p WHERE show_id = 1";
      $r3 = @mysqli_query ($dbc, $q3); // Run the Query.
      while ($nav = mysqli_fetch_array($r3, MYSQLI_ASSOC)) {
      echo"&lt;li&gt;{$nav['link_title']}&lt;/li&gt;"
      }
  ?&gt;
  </code></pre>
  
  <p>This is to show the pages in both the header and footer. </p>
  
  <p>However SOMETIMES the second query in the footer returns a "Couldn't fetch mysqli", sometimes it works, sometimes it doesn't. I was wondering should I be using something like <code>mysqli_free_result()</code> would that be better practice?</p>
  
  <p>Even more, is it good practice to free the result after every query? Is there a better way to use the same result from different pages and <code>&lt;?php // ?&gt;</code> tags?</p>
  
  <p>Also, I get the error "too many mysql connections error" every now and then? Is this because I am not closing connections after queries are ran?</p>