Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm assuming here that you're using an SQL database. <br> Now i haven't tested the code, but i think it should work.</p> <pre><code>// First query to get some info. $testquery = mysql_query("SELECT * FROM `table` WHERE `entity` = 'something'"); if(!$testquery) die(mysql_error()); $total_items = mysql_num_rows($testquery); // Count the total number of entity's that match the criteria. $limit = 10; // Maximun number of entity's on page. $page = $_GET['page']; //calcuate total pages $total_pages = ceil($total_items / $limit); // ceil is used to round up fractions to the next int $set_limit = $page * $limit - ($limit); $query2 = mysql_query("SELECT * FROM `table` WHERE `entity` = 'something' LIMIT $set_limit, $limit"); if(!$query2) die(mysql_error()); //show data matching query: while($code = mysql_fetch_object($query2)) { echo("item: ".$code-&gt;title."&lt;BR&gt;"); } // This displays the "previous page" link if there is a previous page. $prev_page = $page - 1; if($prev_page &gt;= 1) { echo("&lt;a href=yourpagename.php?page=$prev_page&gt;Previous&lt;/a&gt;"); } //Display middle pages: $mid_page = 1; while ($total_pages &gt;= $mid_page) { if ($page == $midpage){ echo ("&lt;b&gt;$mid_page&lt;/b&gt; | "); } else { echo (" &lt;a href=yourpagename.php?page=$mid_page&gt; $mid_page &lt;/a&gt; | "); $midpage++; } } // This page will display a "next page" link if there is one. $next_page = $page + 1; if($next_page &lt;= $total_pages) { echo("&lt;a href=yourpagename.php?page=$next_page&gt;Next&lt;/a&gt;"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      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