$QH =mysql_query ("SELECT count (*) as rcnt from table where Your_condition_here order by whatever"); $data =mysql_fetch_array ($QH); $NR = $data ["rcnt"]; Determine if the offset parameter is passed to the script, and if not, use the default value 0 if (empty ($offset)) { $offset = 0; } Query results (Here are 20 per page, but you can completely change it) $result =mysql_query ("Select Id,name,phone from table where Your_condition_here order by whatever limit $offset, 20"); Show 20 Records returned while ($data =mysql_fetch_array ($result)) { For the code you used to display the return record. } Next, write a link to another page if (! $offset)///If the offset is 0, do not display the link to the previous page { $preoffset = $offset-20; Print "<a href=" $php _self?offset= $preoffset "> previous page </a> "; } Calculate the total number of pages required $pages =ceil ($NR/20); $pages variable now contains the required number of pages for ($i =1; $i <= $pages; $i + +) { $newoffset =20* $i; Print "<a href=" $php _self?offset= $newoffset "> $i </a> "; } Check if it's the last page if ($pages!=0 && ($newoffset/20)!= $pages) { Print "<a href=" $php _self?offset= $newoffset "> next page </a> "; } |