title: Fatal error: Call to a member function fetch_assoc() on a non-object
body: <p>I'm trying to execute a few queries to get a page of information about some images. I've written a function</p>
  
  <pre><code>function get_recent_highs($view_deleted_images=false)
  {
      $lower = $this-&gt;database-&gt;conn-&gt;real_escape_string($this-&gt;page_size * ($this-&gt;page_number - 1));
      $query = "SELECT image_id, date_uploaded FROM `images` ORDER BY ((SELECT SUM( image_id=`images`.image_id ) FROM `image_votes` AS score) / (SELECT DATEDIFF( NOW( ) , date_uploaded ) AS diff)) DESC LIMIT " . $this-&gt;page_size . " OFFSET $lower"; //move to database class
      $result = $this-&gt;database-&gt;query($query);
      $page = array();
      while($row = $result-&gt;fetch_assoc())
      {
          try
          {
              array_push($page, new Image($row['image_id'], $view_deleted_images));
          }
          catch(ImageNotFoundException $e)
          {
              throw $e;
          }
      }
      return $page;
  }
  </code></pre>
  
  <p>that selects a page of these images based on their popularity. I've written a <code>Database</code> class that handles interactions with the database and an <code>Image</code> class that holds information about an image. When I attempt to run this I get an error.</p>
  
  <pre><code>Fatal error: Call to a member function fetch_assoc() on a non-object
  </code></pre>
  
  <p><code>$result</code> is a mysqli resultset, so I'm baffled as to why this isn't working.</p>