简体   繁体   中英

PHP: Display number of links based on variable

I have a variable $h , which counts the number of properties in my foreach . I then have a number stored in $nb_elem_per_page to limit the number of properties shown 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.

Is there a way for me, using the number from $sum_total create links for the number here, such as:

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? 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM