title: SQL Count total number of rows whilst using LIMIT
body: <p>I'm trying to create a simple image gallery, showing 16 images per page.  I'm using LIMIT 16 to display the correct amount on the page, but if there are more than 16 rows, I want to have links at the bottom, allowing the user to navigate to the next page.  </p>
  
  <p>I know I could achieve the desired result by removing the limit and simply using a loop to display the first 16 items, but this would be inefficient.  Obviously, COUNTING the number of rows would always = 16.</p>
  
  <pre><code>$sql .= "posts p, images im, postimages pi WHERE
      i.active = 1 
      AND pi.post_id = p.id
      AND pi.image_id = im.image_id 
      ORDER BY created_at LIMIT 16";
  </code></pre>
  
  <p>Can anyone suggest a more efficient way of doing it?</p>
  
  <p>Thanks</p>