PHP pagination using associative array

PHP pagination using associative array

In this tutorial I am going to show you how to create a pagination in PHP using associative array with working tutorial.
<?php
$state=array(“Andhra Pradesh”=>”Hyderabad”,”Arunachal Pradesh”=>” Itanager”,”Assam”=>”dispur”,”Bihar”=>”Patna”,”Chhattisgarh”=>”Raipur”,”Goa”=>”Panaji”,
“Gujarat”=>”Ahmedabad”,”Haryana”=>”Chandigarh”,”HimachalPradesh”=>”Shimla”,
“Mizoram”=>”Aizawl”,”Jammu&Kashmir”=>”Srinagar”,”Jharkhand”=>”Ranchi”,
“Krnataka”=>”Bangalore”,”Kerala”=>”Thiruvanthapuram”,”Madhya Pradesh”=>”Bhopal”,”Maharashtra”=>”Mumbai”,”Manipur”=>”Imphal”,”Meghalaya”=> “Shillong”,”Nagaland”=>”Kohima”,”Orissa”=>”Bhubaneswar”,”Punjab”=>”Chandigarh”,
“Sikkim”=>”Gangtok”,”Rajasthan”=> “Jaipur”,”Tamil Nadu”=>”Chennai”,”Tripura”=>”Agartala”,
“Uttar Pradesh”=>”Lucknow”,”Uttarakhand”=>”Dehra Dunm”,”West Bengal”=>”Culcutta”);
?>
<table width=”380″ border=”1″ align=”center”>
<tr>
<td width=”370″ height=”23″><center>
<?php
$link_no=$_REQUEST[‘lid’];  //receive link link no which have clicked.
if(empty($link_no))   //if nothing is clicked default value of $link will 1;
$link_no=1;
$end=$link_no*5; // ending point.
$start=$end-5;// starting point
$i=1;
echo”<table border=’1′>”;
echo “<tr><th>State</th><th>Capital</th></tr>”;
foreach($state as $st=>$cp)
{
if($i>$start&&$i<=$end)
echo “<tr><td>$st</td><td>$cp</td></tr>”;
$i++;
}
echo”</table>”;
?></td>
</tr>
<tr>
<td height=”23″>
<?php
$data=count($state);
$num_link=ceil($data/5);  //count how many link will create(5 of 5)
for($i=1;$i<=$num_link;$i++)
echo “<a href=’paging.php?lid=$i’ style=’text-decoration : none’>$i</a>”.” “;
//link generate and query string is pass.
?>

</td>
</tr>
</table>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do you have any Query / Suggestion