title: How to include file multiple times in PHP?
body: <p>I have a standardized sequence of code which I used to display topic information on the home page and other pages on my site. I want to throw it in an include file so that I don't have to keep fixing multiple pages. The problem is sometimes this include occurs in a while statement which means there was a previous query supplying information for sorting purposes. </p>
  
  <p>When the code is raw in the while statement, it works as it should and if there are multiple ids being served to the code from the previous query, it shows multiple results. However, if this code is in an include, I will only see one result. I assume because the include file only executes once. How would I serve an include file as the equivalent as my raw code?</p>
  
  <p><strong>Include</strong></p>
  
  <pre><code>//outside query
  while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC))
  {
      $topic_id=htmlspecialchars( $row['topic_id'], ENT_NOQUOTES, 'UTF-8' );
      //code to display topics
      include('display_topics.php');  
  }
  </code></pre>
  
  <p><strong>Raw Code</strong></p>
  
  <pre><code>//outside query
  while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC))
  {
      //code to display topics
      $sql = "SELECT * FROM topic WHERE id=?";
      $stmt = $conn-&gt;prepare($sql);
      $stmt-&gt;bindValue(1,topic_id, PDO::PARAM_INT);
      $result=$stmt-&gt;execute();
  }
  
  while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC))
  {
      //yada yada
      ...
  }
  </code></pre>