Skip to main content

Posts

Showing posts from November, 2014

Pagination on PHP

Its always possible that your SQL SELECT statement query may result into thousand of records. But its is not good idea to display all the results on one page. So we can divide this result into many pages as per requirement. Paging means showing your query result in multiple pages instead of just put them all in one long page. MySQL helps to generate paging by using LIMIT clause which will take two arguments. First argument as OFFSET and second argument how many records should be returned from the database. Below is a simple example to fetch records using LIMIT clause to generate paging. Example: Try out following example to display 10 records per page. Paging Using PHP $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $rec_limit = 10; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) {   die('Could not connect: ' . mysql_error()); } mysql_select_db('test_db'); /* Get total number of