Paging, number of items per page and offset

  • page: X
  • nb_per_page: Y
  • => OFFSET = (X-1)*Y
  • =>OFFSET = (page-1)*nb_per_page

Easy, no?

27. août 2009 par Saad Tazi
Catégories: programmation, tips | Tags: , | 2 commentaires

(2) commentaires

  1. So your query would end with this?
    LIMIT $nb_per_page, $offset

  2. For MySQL : LIMIT $nb_per_page, $offset

    With postgreSQL: limit $nb_per_page offset $offset.

    With MS SQL, you have to use « SELECT TOP $nb_per_page » but for the offset, it’s more complex, because you have to « calculate the offset and use a WHERE statement (something like: « WHERE ID >= $calculated_id)

Laisser un commentaire

Les champs obligatoires sont indiqués avec *

*