TrinityTuts Tips

Simple pagination for your web api or web services

We all know about pagination and where we use :-p but if you are developing web api or web services in php here is a simple and easy way to create pagination.

<?php
	$page = 1; // Default page start with 1 
	$limit = $limit; // Set Limit according to you 1 - 5 -10
	$start = 0;
	if(isset($_POST['page']) && $_POST['page'] !=""){
		$page = $_POST['page'];  // Request page no eg. 1,2,3,4,5
		if(!is_numeric($page)){
			$page = 1;
		}
		$start = ($page - 1)*$limit;
	}
	
	$query = mysql_query("SELECT * FROM  `your_table` where 'condition_is' = '1' order by id desc limit $start, $limit");

hope this help you 🙂