title: PHP using MySQL returning errors sometimes, and working other times, despite me changing nothing
body: <p>I'm having a strange issue with the MySQL I'm using on my site. Some days, in place of my code, I will get:</p>
  
  <p><code>Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in [the current file] on line 14</code></p>
  
  <p>The code is the following:</p>
  
  <pre><code>&lt;?php
  
      include("../../configsql/configsemester.php");
  
      $query="SELECT * FROM duedates_f2011 GROUP BY actualdate";
      $result=mysql_query($query);
      $numrows=mysql_numrows($result);
  
  
      $i=0;
  
      while($i &lt; $numrows)
      {
  
          $actualdate=mysql_result($result,$i,"actualdate");
          $duedate=mysql_result($result,$i,"duedate");
          $styleclass="date"; mysql_result($result,$i,"styleclass");
          $today=date("Y-m-d"); //H:i:s");
          $query2="SELECT * FROM duedates_f2011 WHERE duedate = \"" . $duedate . "\"";
          $result2=mysql_query($query2);
          $numrows2=mysql_numrows($result2);
  
          $k=0;
  
          if( $today &gt; $actualdate)
          { $styleclass="done duedate"; }
          echo "&lt;div class=\"" . $styleclass . "\"&gt;\n\t";
          echo "&lt;h3&gt;" . $duedate . "&lt;/h3&gt;\n";
  
          echo "&lt;ul&gt;\n\t";
          while($k &lt; $numrows2)
          {
              $assignmentname=mysql_result($result2,$k,"assignmentname");
              $duetime=mysql_result($result2,$k,"duetime");
              $coursecode=mysql_result($result2,$k,"coursecode");
              $link=mysql_result($result2,$k,"link");
  
              //echo "&lt;div class=\"" . $styleclass . "\"&gt;\n\t";
              if(is_null($link)) { echo "&lt;li&gt;" . $coursecode . ": " . $assignmentname . " @ " . $duetime . "&lt;/li&gt;"; } else { echo "&lt;li&gt;&lt;a href=\"" . $link . "\"&gt;" . $coursecode . ": " . $assignmentname . " @ " . $duetime . "&lt;/a&gt;&lt;/li&gt;"; }
              //echo "&lt;li&gt;" . $coursecode . ": " . $assignmentname . " @ " . $duetime . "&lt;/li&gt;";
              $k++;
          }
          echo "\n&lt;/ul&gt;\n";
          $i++;
          if($i != $numrows)
          {
              echo "&lt;hr class=\"nonmobile\" /&gt;\n"; //so that it is not displayed at the end, also this must be inside the &lt;div&gt; so that it is included 
          }
          echo "&lt;/div&gt;\n\n";
      }
      mysql_close();
  
  ?&gt;
  </code></pre>
  
  <p>It should be noted that the code above is part of a page which is include()'d inside another page, which also use MySQL. I have made sure to open/close the database at the appropriate spots in this exterior code, though, and again, it usually works.</p>
  
  <p>I'm just wondering what would be causing these errors to come about, only sometimes.</p>