Note that there are some explanatory texts on larger screens.

plurals
  1. POReversing page navigation on PHP
    primarykey
    data
    text
    <p>Can anyone help me with reversing this PHP page navigation?</p> <p>Current script setting shows this format: [0] | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ... 14 • Forward > • End >>></p> <p>But I really need it to reverse for this format: [14] | 13 | 12 | 11| 10 | 9 | 8 | 7 | 6 ... 0 • Back > • Start >>></p> <p>Here is the PHP code:</p> <pre><code>&lt;? $onpage = 10; // on page function page(){ if(empty($_GET["page"])){ $page = 0; } else { if(!is_numeric($_GET["page"])) die("Bad page number!"); $page = $_GET["page"]; } return $page; } function navigation($onpage, $page){ //---------------- $countt = 150; $cnt=$countt; // total amount of entries $rpp=$onpage; // total entries per page $rad=4; // amount of links to show near current page (2 left + 2 right + current page = total 5) $links=$rad*2+1; $pages=ceil($cnt/$rpp); if ($page&gt;0) { echo "&lt;a href=\"?page=0\"&gt;&lt;&lt;&lt; Start&lt;/a&gt; &lt;font color='#CCCCCC'&gt;•&lt;/font&gt; &lt;a href=\"?page=".($page-1)."\"&gt;&lt; Back&lt;/a&gt; &lt;font color='#CCCCCC'&gt;•&lt;/font&gt;"; } $start=$page-$rad; if ($start&gt;$pages-$links) { $start=$pages-$links; } if ($start&lt;0) { $start=0; } $end=$start+$links; if ($end&gt;$pages) { $end=$pages; } for ($i=$start; $i&lt;$end; $i++) { echo " "; if ($i==$page) { echo "["; } else { echo "&lt;a href=\"?page=$i\"&gt;"; } echo $i; if ($i==$page) { echo "]"; } else { echo "&lt;/a&gt;"; } if ($i!=($end-1)) { echo " &lt;font color='#CCCCCC'&gt;|&lt;/font&gt;"; } } if ($pages&gt;$links&amp;&amp;$page&lt;($pages-$rad-1)) { echo " ... &lt;a href=\"?page=".($pages-1)."\"&gt;".($pages-1)."&lt;/a&gt;"; } if ($page&lt;$pages-1) { echo " &lt;font color='#CCCCCC'&gt;•&lt;/font&gt; &lt;a href=\"?page=".($page+1)."\"&gt;Forward &gt;&lt;/a&gt; &lt;font color='#CCCCCC'&gt;•&lt;/font&gt; &lt;a href=\"?page=".($pages-1)."\"&gt;End &gt;&gt;&gt;&lt;/a&gt;"; } } $page = page(); // detect page $navigation = navigation($onpage, $page); // detect navigation ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload