[英]PHP: Display number of links based on variable
I have a variable $h
, which counts the number of properties in my foreach
.我有一个变量$h
,它计算我的foreach
的属性数量。 I then have a number stored in $nb_elem_per_page
to limit the number of properties shown per page.然后我在$nb_elem_per_page
存储了一个数字来限制每页显示的属性数量。
<?php $sum_total = ceil($h / $nb_elem_per_page); ?>
I then use the above to work out how many pages these will need.然后我使用上面的来计算这些需要多少页。 For example $nb_elem_per_page
is currently 12. So if $h
was 123 it would need 11 pages.例如, $nb_elem_per_page
当前为 12。因此,如果$h
为 123,则需要 11 页。
Is there a way for me, using the number from $sum_total
create links for the number here, such as:我有没有办法,使用$sum_total
中的数字为此处的数字创建链接,例如:
http://www.website.co.uk/properties/search/?bed=4&go=1
http://www.website.co.uk/properties/search/?bed=4&go=2
http://www.website.co.uk/properties/search/?bed=4&go=3
So it outputs the number of links based on the number in $sum_total
, but on each one the end number goes up 1 each time as above?所以它根据$sum_total
的数字输出链接的数量,但在每个链接上,结束数字每次都增加 1 如上所述? This would then be my pagination.这将是我的分页。
for ($i = 1; $i < $sum_total; $i++) {
echo "<a href=\"http://www.website.co.uk/properties/search/?bed=4&go={$i}\">{$i}</a>";
}
Or whatever you would like.或者任何你想要的。 You can refer to php's documentation here : http://php.net/manual/en/control-structures.for.php您可以在此处参考 php 的文档: http : //php.net/manual/en/control-structures.for.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.