title: PHP + MySql Pagination with categories and no offset
body: <p>I'm working with online marketplace site where users can sell their own stuff and visitors can browse marketplace by categories.</p>
  
  <p>I have been reading about mysql pagination that if you use limit with offset, it will use alot resources and takes long time to execute if its huge database.</p>
  
  <p>So, I don't want to use "LIMIT 10000, 20" as example, only if its last choise.</p>
  
  <p>If there was no categories, this would do fine
  "SELECT * FROM products WHERE id > 10000 LIMIT 20"</p>
  
  <p>But, as there is categories for products involved, I can't use that.
  Lets say that first product added to category id 10 is added after there is 2000 products in whole database. That product would get ID 2001.</p>
  
  <p>So if I would browse first page of category id 10, this query would run:
  "SELECT * FROM products WHERE catid = 10 LIMIT 20"</p>
  
  <p>If I go to next page, this runs:
  "SELECT * FROM products WHERE catid = 10 AND id > 20 LIMIT 20"</p>
  
  <p>So, basicly visitor would see product 2001 in every page until he hits page 101 when query looks for products that id is over 2020 and thats why I can't use "WHERE id > something" in query.</p>
  
  <p>Long story short, whats best way to deal with pagination when working with categories and doesnt eat so much performance?</p>