cameronmarklewis
cameronmarklewis

Reputation: 264

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.

Upvotes: 1

Views: 32

Answers (1)

Mathieu de Lorimier
Mathieu de Lorimier

Reputation: 1015

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

Upvotes: 1

Related Questions