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:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in [the current file] on line 14
The code is the following:
<?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 < $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 > $actualdate)
{ $styleclass="done duedate"; }
echo "<div class=\"" . $styleclass . "\">\n\t";
echo "<h3>" . $duedate . "</h3>\n";
echo "<ul>\n\t";
while($k < $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 "<div class=\"" . $styleclass . "\">\n\t";
if(is_null($link)) { echo "<li>" . $coursecode . ": " . $assignmentname . " @ " . $duetime . "</li>"; } else { echo "<li><a href=\"" . $link . "\">" . $coursecode . ": " . $assignmentname . " @ " . $duetime . "</a></li>"; }
//echo "<li>" . $coursecode . ": " . $assignmentname . " @ " . $duetime . "</li>";
$k++;
}
echo "\n</ul>\n";
$i++;
if($i != $numrows)
{
echo "<hr class=\"nonmobile\" />\n"; //so that it is not displayed at the end, also this must be inside the <div> so that it is included
}
echo "</div>\n\n";
}
mysql_close();
?>
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.
I’m just wondering what would be causing these errors to come about, only sometimes.
if you put
before the ; on line 14
you will get the full explanation the next time it crashes