Php 数组分页-编写数学公式
我的问题与上一个关于数组分页的问题几乎相似 如果Php 数组分页-编写数学公式,php,arrays,oop,Php,Arrays,Oop,我的问题与上一个关于数组分页的问题几乎相似 如果CurrentPage=1那么我想要StartPage=20,如果CurrentPage=2那么StartPage=15,如果CurrentPage=3那么StartPage=10,如果CurrentPage=4那么StartPage=5 请注意,如果5是由于每页的行数不同造成的,则可能会发生变化。因此,如果是10,如果CurrentPage=1那么StartPage=20,如果CurrentPage=2那么StartPage=10 我只是想知道我
CurrentPage=1
那么我想要StartPage=20
,如果CurrentPage=2
那么StartPage=15
,如果CurrentPage=3
那么StartPage=10
,如果CurrentPage=4
那么StartPage=5
请注意,如果5是由于每页的行数不同造成的,则可能会发生变化。因此,如果是10,如果CurrentPage=1
那么StartPage=20
,如果CurrentPage=2
那么StartPage=10
我只是想知道我是怎么写数学方程式的
例如,我写了这样的东西
$RowsPerPage = 5;
$StartPage = $RowsPerPage * ( RowsPerPage - $CurrentPage);
但是,仅当RowsPerPage
设置为5时,上述操作才起作用
有什么建议吗???这可能是您想要的:
$StartPage = 20 - (($CurrentPage - 1) * $RowsPerPage);
这应该是你想要的。谢谢@Jon。正是我需要的
$RowsPerPage = 5;
$TotalPages = 20;
$StartPage = $TotalPages - ( ( $CurrentPage - 1 ) * $RowsPerPage );