title: How can I avoid stuck processes?
body: <p>If I comment out the following code from the page, it works fine.
  But if the code in, processes stuck and the site slows down and I get  500 server error.</p>
  
  <p>If someone click on a series datasheet it loads the episodes.
  And if choose an episode and click on it loads the online links and scroll down</p>
  
  <pre><code>&lt;a name="online"&gt;&lt;/a&gt;
  &lt;br&gt;&lt;h4 id="b" style="padding-left: 15px;"&gt;Episodes:&lt;/h4&gt;
  &lt;div class="blog-pagenat-wthree"&gt;
  &lt;ul&gt;
  &lt;?php
  $query = "SELECT episode FROM episodes WHERE seriesid = ? ORDER BY episode LIMIT 1";
  $stmt = $conn-&gt;prepare($query);
  $stmt-&gt;bind_param('i', $id);
  $stmt-&gt;execute();
  $stmt-&gt;bind_result($firstepisode);
  $stmt-&gt;fetch();
  $stmt-&gt;close();
  
  $query = "SELECT episode FROM episodes WHERE seriesid = ?";
  $stmt = $conn-&gt;prepare($query);
  $stmt-&gt;bind_param('i', $id);
  $stmt-&gt;execute();
  $stmt-&gt;store_result();
  $allepisode = $stmt-&gt;num_rows;
  $stmt-&gt;close();
  
  $title2 = str_replace(array("'"), array("\'"), $title);
  $title3 = sanitize($title2);
  $season = explode(". season", $title2);
  $season2 = explode(" - ", $season[0]);
  
  for($i=$firstepisode; $i&lt;=$allepisode; $i++)
  {
      echo "&lt;li&gt;&lt;a href='mysite/".$id."/".$title3."-series/".$i."-episode#online'&gt;".$i."&lt;/a&gt;&lt;/li&gt; ";
  }
  ?&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I tried to comment out just the code which loads the links but I think this part case the stuck processes.</p>