Note that there are some explanatory texts on larger screens.

plurals
  1. POpaging in php to show 123....7 instead of 1234567?
    primarykey
    data
    text
    <p>well i have a class pagination </p> <pre><code>&lt;?php class Pagination { public $current_page; public $per_page; public $total_count; public function __construct($page=1, $per_page=20, $total_count=0){ $this-&gt;current_page = (int)$page; $this-&gt;per_page = (int)$per_page; $this-&gt;total_count = (int)$total_count; } public function offset() { return ($this-&gt;current_page - 1) * $this-&gt;per_page; } public function total_pages() { return ceil($this-&gt;total_count/$this-&gt;per_page); } public function previous_page() { return $this-&gt;current_page - 1; } public function next_page() { return $this-&gt;current_page + 1; } public function has_previous_page() { return $this-&gt;previous_page() &gt;= 1 ? true : false; } public function has_next_page() { return $this-&gt;next_page() &lt;= $this-&gt;total_pages() ? true : false; } } ?&gt; </code></pre> <p>and here is how i use this in index.php</p> <pre><code>&lt;?php $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 4; $total_count = class::count_all(); $pagination = new Pagination($page, $per_page, $total_count); $sql = "SELECT * FROM tablename "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination -&gt; offset()}"; ?&gt; &lt;?php foreach($variables as $variable): ?&gt; &lt;?php endforeach;?&gt; &lt;?php if ($pagination -&gt; total_pages() &gt; 1) { if ($pagination -&gt; has_previous_page()) { echo "&lt;a href=\"index.php?page="; echo $pagination -&gt; previous_page(); echo "\"&gt;&amp;laquo; Previous&lt;/a&gt; "; } for ($i = 1; $i &lt;= $pagination -&gt; total_pages(); $i++) { if ($i == $page) { echo " &lt;span class=\"selected\"&gt;{$i}&lt;/span&gt; "; } else { echo " &lt;a href=\"index.php?page={$i}\"&gt;{$i}&lt;/a&gt; "; } } if ($pagination -&gt; has_next_page()) { echo " &lt;a href=\"index.php?page="; echo $pagination -&gt; next_page(); echo "\"&gt;Next &amp;raquo;&lt;/a&gt; "; } } ?&gt; </code></pre> <p>my problem is if there are alot of pages i want it to out put 1 2 3 ....... 10 instead of 1 2 3 4 5 6 7 8 9 10</p> <p>Thanks in advance and i am really sorry for annoying all of you like this</p>
    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.
    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