title: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
body: <p>I've looked over several SO posts, as well as articles on other websites, and have yet to find a valid answer :(.</p>
  
  <p><strong>Here's my code:</strong></p>
  
  <pre><code>include("db_conn.php");
  $conn = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error());
  
  $timestamp = time();
  $add_time = time()+(60*60);
  
  $query = "SELECT * FROM links WHERE timestamp &gt;= '$timestamp' AND overflow = 'NO'";
  $result = mysql_query($query);
  
  if(mysql_num_rows($result) &gt; 0) {
  while($row = mysql_fetch_assoc($result)){
          $link = $row['link'];
          $hit_update = rand($row['min'],$row['max']);
  
          $query = "UPDATE links SET timestamp = '$add_time', hit_counter = '0', max_hits = '$hit_update' WHERE link = '$link' AND timestamp &lt;= '$timestamp' AND overflow = 'NO'";
          $result = mysql_query($query) or die(mysql_error());
  }
  }
  
  mysql_close($conn);
  </code></pre>
  
  <p><strong>It returns the error:</strong></p>
  
  <pre><code>Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
  </code></pre>
  
  <p><strong>To diagnose I've tried:</strong></p>
  
  <ul>
  <li>Removing the encasing <code>if()</code> statement.</li>
  <li>Commenting out the <code>while()</code> loop, and adding <code>$size = mysql_num_rows($result); echo $size;</code> below <code>$result = mysql_query($query);</code> which returns <code>3</code>, i.e. there's nothing wrong with the query itself.</li>
  </ul>
  
  <p>Does anyone know what the problem could be?</p>
  
  <p>Any answers would be very much appreciated!!</p>