Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In order to do this you also need to use the offset value in your SQL Statement, so it would be </p> <pre><code>SELECT * FROM users LIMIT $offset, $perpage </code></pre> <p>Example:</p> <pre><code>SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15 </code></pre> <p>Then to get the links to put on the bottom of your page you would want to get a count of the total data, divide the total by the per page value to figure out how many pages you are going to have.</p> <p>Then set your offset value based on what page the user clicked.</p> <p>Hope that helps!</p> <p>Update:</p> <p>The unexpected end most likely means that you have an extra closing bracket } in your code which is causing the page to end and still has more code after it. Look through your code and match up the brackets to fix that. There are a few other issues in the code sample you pasted.</p> <pre><code>$result = mysql_query("SELECT * FROM users" ); //Note if you have a very large table you probably want to get the count instead of selecting all of the data... $nrResults = mysql_num_rows( $result ); if( $_GET['page'] ) { $page = $_GET['page'] } else { $page = 1; } $per_page = 2; $offset = ($page - 1) * $per_page; //So that page 1 starts at 0, page 2 starts at 2 etc. $result = mysql_query("SELECT * FROM users LIMIT $offset,$per_page"); while( $line = mysql_fetch_array( $result ) ) { //Do whatever you want with each row in here } </code></pre> <p>Hope that helps</p> <p>You can then use the nrResults number to figure out how many pages you are going to have... if you have 10 records and you are displaying 2 per page you would then have 5 pages, so you could print 5 links on the page each with the correct page # in the URL...</p>
 

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