配列のページネーションに取り組んでいます。方程式を立てるのに苦労しています。私が欲しいのはいつですか
$CurrentPage = 1 then $Start = 1,
if $CurrentPage = 2 then $Start = 30,
if $CurrentPage = 3 then $Start = 60,
if $CurrentPage = 4 then$Start = 90
等々..
if else ブロックの書き方
配列のページネーションに取り組んでいます。方程式を立てるのに苦労しています。私が欲しいのはいつですか
$CurrentPage = 1 then $Start = 1,
if $CurrentPage = 2 then $Start = 30,
if $CurrentPage = 3 then $Start = 60,
if $CurrentPage = 4 then$Start = 90
等々..
if else ブロックの書き方
これを使用することもできます:
$Start = ($currentPage==1 ? 1 : ($currentPage-1)*30);
すべての if/else を忘れてください。
現在のページが 1 の場合、結果 1 から表示します (結果 0 からではない何らかの理由で)。1 ページよりも大きい場合は、結果から表示します (ページ - 1)*30
if ((int)$currentPage > 1) {
$start = ($currentPage - 1)*30;
}
else {
$start = 1;
}
またはより短い方法で
$start = ($currentPage > 1) ? ((int)$currentPage - 1) * 30 : 1;
複雑にしないでおく:
$Start = max(1, ($currentPage-1) * 30);