Hello, I've written a very simple script to give me information from a database. It seems to work 95% of the time, but the other 5%, I get errors relating to an invalid result set. Here is the code:
<?php
echo "<b>Recent Referrals</b><br>";
$dbh=@mysql_connect ("localhost", "xxxxxx", "xxxxxx");
if ($dbh) {
mysql_select_db ("bionic_refer");
$query = "SELECT refer, unix_timestamp( time ) AS stamp, max( TIME ) max_time FROM refer WHERE time > date_sub( now( ) , INTERVAL 2 HOUR ) GROUP BY refer ORDER BY `max_time` DESC LIMIT 5";
$result=mysql_query($query);
$num=mysql_numrows($result); // error happens here...
$i=0;
while ($i < $num) {
$refer=mysql_result($result,$i,"refer");
echo "<a href=\"http://www.$refer\">$refer</a><br>";
++$i;
}
mysql_close();
} else {
echo "<!-- " . mysql_error() . " -->";
}
?>
Any ideas what might cause this result set error to pop up every so often?
-Sonny