number Pagination with drop down box to limit number of pages in php


number Pagination with drop down box to limit number of pages in  php

drop down box Code:

<form action=”” method=”GET” id=”pagination” name=”pagination”>

<tr>

<td>DISPLAY

<input type=”HIDDEN” value=”<?php if(isset($_GET[‘mydisplaylimit’])) echo $_GET[‘mydisplaylimit’];?>”  id=”limits” name=”limits”> <select style=”border: 2px outset rgb(204, 51, 0);” size=”1″ name=”mydisplaylimit” id=”mydisplaylimit” >

<?php $default_limit = isset($_GET[‘mydisplaylimit’]) ? $_GET[‘mydisplaylimit’] : 5; foreach (array(5, 10, 20, 50) as $option) {     ?>

    <option value=”<?php echo $option ?>” <? if($option == $default_limit) { echo “selected”; } ?> <?php echo $option;?></option>     <?php } ?>  

</select><input type=”SUBMIT” value=”GO”  style=”border: 2px outset rgb(204, 51, 0);” onclick=”$(‘#limits’).val($(‘#mydisplaylimit’).val())”>

</td>

</tr> 

</form>

$mid_range = 5;
if(isset($_GET['limits']))
{
$pages = ceil($nb_ips/$_GET['limits']);
}
else
{
$pages = ceil($nb_ips/25);
}
echo '<tr>';
if(isset($_GET['pageno'])){
$pagenumber = $_GET['pageno'];
}
if(isset($pagenumber))
$current_page= $pagenumber;
else
$current_page=1;
if($current_page < 1 || !is_numeric($current_page)) $current_page = 1;
if($current_page > $pages) $current_page = $pages;
$start_range = $current_page - floor($mid_range/2);
$end_range = $current_page + floor($mid_range/2);
if($start_range <= 0)
{
$end_range += abs($start_range)+1;
$start_range = 1;
}
if($end_range > $pages)
{
$start_range -= $end_range-$pages;
$end_range = $pages;
}
if(isset($_GET['pageno'])){
$prev = $pagenumber-1;
if($prev>0)
echo '<td><a href="manage_ip2.php?pageno='.$prev.'&limits='.$_GET['limits'].'"   
style="cursor: hand;cursor: pointer;font-size:18px"   >previous</a></td>';
}
if($pages>1){

$range = range($start_range,$end_range);

for($i=1; $i<=$pages; $i++)
{
if($range[0] > 2 && $i == $range[0])
echo $return .= " ... ";
else $range[]=3;
if($i==1 || $i==$pages || in_array($i,$range))
{
if($pagenumber==$i)
echo '<td id="'.$i.'"><a href="manage_ip2.php?pageno='.$i.'&limits='.$_GET['limits'].'"  
style="color:#fff;background-color:#006699;"  id="but'.$i.'" 
 style="cursor: hand;cursor: pointer;font-size:18px">'.$i.'</a></td>';
else
echo '<td id="'.$i.'"><a href="manage_ip2.php?pageno='.$i.'&limits='.$_GET['limits'].'" 
   id="but'.$i.'"  style="cursor: hand;cursor: pointer;font-size:18px">'.$i.'</a></td>';
}
if($range[$mid_range-1] < $pages-1 && $i == $range[$mid_range-1])
echo $return .= " ... ";
}if(isset($pagenumber)){
$next = $pagenumber + 1;
if($next <= $pages)
{
echo '<td id="'.$next .'"><a href="manage_ip2.php?pageno='.$next.'&limits='.$_GET['limits'].'"   
style="cursor: hand;cursor: pointer;font-size:18px"  >NEXT</a></td>';
}
}
}echo '</tr>';
Advertisements
About

myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , , , , , , , , , , ,
Posted in number Pagination with drop down box to limit number of pages in php, Practice Makes a beginner to become php programmer expert(practical task to become php programmer)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow php tutorial on WordPress.com
categories
Calendar
October 2013
M T W T F S S
« Sep   Nov »
 123456
78910111213
14151617181920
21222324252627
28293031  
Follow me on Twitter
Blog Stats
  • 75,930 hits
%d bloggers like this: