Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my php learning books, it provides a solution using a PHP class it looks like this</p> <pre><code>&lt;!-- language: php --&gt; &lt;?php error_reporting(0); // disable the annoying error report class page_class { // Properties var $current_page; var $amount_of_data; var $page_total; var $row_per_page; // Constructor function page_class($rows_per_page) { $this-&gt;row_per_page = $rows_per_page; $this-&gt;current_page = $_GET['page']; if (empty($this-&gt;current_page)) $this-&gt;current_page = 1; } function specify_row_counts($amount) { $this-&gt;amount_of_data = $amount; $this-&gt;page_total= ceil($amount / $this-&gt;row_per_page); } function get_starting_record() { $starting_record = ($this-&gt;current_page - 1) * $this-&gt;row_per_page; return $starting_record; } function show_pages_link() { if ($this-&gt;page_total &gt; 1) { print("&lt;center&gt;&lt;div class=\"notice\"&gt;&lt;span class=\"note\"&gt;Halaman: "); for ($hal = 1; $hal &lt;= $this-&gt;page_total; $hal++) { if ($hal == $this-&gt;current_page) echo "$hal | "; else { $script_name = $_SERVER['PHP_SELF']; echo "&lt;a href=\"$script_name?page=$hal\"&gt;$hal&lt;/a&gt; |\n"; } } } } } ?&gt; </code></pre> <p>then we call it on the script that require paging</p> <pre><code>&lt;!-- language: php --&gt; &lt;?php $per_page = 5; $page = new Page_class($per_page); error_reporting(0); // disable the annoying error report $sql="SELECT * FROM table WHERE condition GROUP BY group"; $result=mysql_query($sql) or die('error'.mysql_error()); // paging start $row_counts = mysql_num_rows($result); $page-&gt;specify_row_counts($row_counts); $starting_record = $page-&gt;get_starting_record(); $sql="SELECT * FROM table WHERE condition GROUP BY group LIMIT $starting_record, $per_page"; $result=mysql_query($sql) or die('error'.mysql_error()); $number = $starting_record; //numbering $num_rows = mysql_num_rows($result); if ($num_rows == 0 ) { // if no result is found echo "&lt;div class=\"notice\"&gt; &lt;center&gt;&lt;span class=note&gt;NO DATA&lt;/span&gt;&lt;/center&gt; &lt;/div&gt;"; } else { // while goes here ... } ?&gt; // call the page link &lt;?php $page-&gt;show_pages_link(); ?&gt; </code></pre> <p>hope it helps, just tried it hours ago to my search script page (learning from books)</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.
    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