Skip to content

Instantly share code, notes, and snippets.

@lon9
Last active September 5, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lon9/6c149c26a5c59b11355d to your computer and use it in GitHub Desktop.
Save lon9/6c149c26a5c59b11355d to your computer and use it in GitHub Desktop.
Webページのページングの時に必要になる超簡単なアルゴリズム ref: http://qiita.com/Rompei/items/cc4ca6cffa2fd3c3930a
p:ページナンバー
m:1ページに表示したい項目数
問:sql文を作成したい=>SQLのl:Limitとo:Offsetを求める。また、初期値としてそれぞれl=M,o=0とする。
アルゴリズム:
l=m
o=(p-1)*l
n:全項目数
p:ページナンバー
m:1ページに表示したい項目数
問:そのページが最後のページか判定したい。
例:例えば、最後のページでは「次へ」などのインジケータを消したい。
アルゴリズム:
if n-m*p<=0 then
return true
else
return false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment