I get count (id) example 60

How to do so to display in the form: 1-10,10-20,20-30,30-40,40-50-50,50-60

    3 answers 3

    Maybe I'm wrong, but there is a bike on the webew and I would say not very bad.

    Pages: previous 1-20 21-40 41-60 61-80 81-100 next

      <?php $pageSize = 10; $page = isset($_GET['page']) ? (int) $_GET['page'] : 0; $pages = ceil($count / $pageSize); $query = mysql_query('SELECT * FROM table LIMIT ' . $page . ', ' . $pageSize); while($row = mysql_fetch_array($query)) { //вывод записей } foreach($i = 1; $i <= $pages; $i++) { if($page === $i { echo '<b><a href="?page=' . ($i - 1) . '">' . $i . '</a></b> '; } else { echo '<a href="?page=' . ($i - 1) . '">' . $i . '</a> '; } } 
      • HTTP ERROR 500 somewhere I can’t find xD - Sauron
      • @alias, you need to display page navigation in the format 1-10,10-20-20,20-30,30-40,40-50,50-60, and you get 1,2,3,4,5,6 - cheops
      • echo '<a href="?page='. ($i-1).'">'. ($ i * 10). '</a>'; - alias

      Maybe some of this will suit you:

       <?php $records = 65; $on_page = 10; $page_count = ceil($records / $on_page); /** * Вариант под Ваши условия */ for ($i = 0; $i < $page_count; $i++) { $int_begin = ($i * 10); if ($int_begin == 0) { $int_begin = 1; } $int_end = (($i + 1) * 10); if ($int_end > $records) { $int_end = $records; } echo "[" . $int_begin . "-" . $int_end . "]"; } /** * И, как мне кажется, более правильный вариант. * Т.к. если первая страница оканчивается 10 записью, то вторая должна начинаться с 11 */ for ($i = 0; $i < $page_count; $i++) { $int_end = (($i + 1) * 10); if ($int_end > $records) { $int_end = $records; } echo "[" . ($i * 10 + 1) . "-" . $int_end . "]"; }