Re: Paging script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

Maybe it is not just what you need but could be helpfull.

Here you have the code:

//-------------------paginator.php----------------------------------------------------------------------------
<?php
function paginator ($current, $total, $per_page, $link, $limit) {

    if ($current == '')
    {
    $current = 1;
    }else{
    $current = $current;
    }

  $total_pages = ceil($total/$per_page);
  $previous = $current - 1;
  $next = $current + 1;


/*traduction*/
  $toFrom = "<p>Page ".$current." of ".$total_pages."</p>";
  $Goto = "Go to Page";
  $go = "Go";


  $texto = "
  <div id='paginacion'>".$toFrom."
  <ul>";

  if ($current > 1)
    $texto .= "<li><a href=\"$link$previous\">&laquo;</a></li>";
  else
    $texto .= "<li><b>&laquo;</b></li>";


//Se lista hasta llegar a la posición actual
    if ($current > $limit) {
    $start = ($current - $limit) + 1;
    $texto .= "<li><b>...</b></li>";
    } else {
    $start = 1;
    }

     for ($start; $start < $current; $start++) {
           $texto .= "<li><a href=\"$link$start\">$start</a></li>";
   }

//mostramos posicion actual
  $texto .= "<li><b>$current</b></li> ";

//mostramos resto de registros
  for ($i=$current+1; $i<=$total_pages; $i++) {

          if ($i > $limit)
          {
          $texto .= "<li><b>...</b></li>";
          $i = $total_pages;
          }else{
          $texto .= "<li><a href=\"$link$i\">$i</a></li> ";
          }
    }

  if ($current < $total_pages)
  {
      $texto .= "<li><a href=\"$link$next\">&raquo;</a></li>";
  }else{
    $texto .= "<li><b>&raquo;</b></li>";
  }

 $texto .= "</ul>";


 //a form to go directly to the page you want
 $texto .= '<!--FORMULARIO PAGINADOR-->
<div id="form_ir">
    <form action="'.$_SERVER["PHP_SELF"].'" method="get">
        <fieldset>
            <p>'.$Goto.' <input type="text" size="3" name="page" value="" />
            <input type="submit" name="ir" value="'.$go.'" /></p>
        </fieldset>
    </form>
</div>';



$texto .= '<br class="break" />

</div>
';

return $texto;

}

?>
//-------------------paginator.php----------------------------------------------------------------------------

//-------------------example.php----------------------------------------------------------------------------
<?php
include ("paginator.php");

for ($n=0; $n<=100; $n++)
{
$myArray [$n] = $n;
}

$total = count ($myArray); //the total elements in the array
$per_page = 5; //elements the script show
$link = "example.php?page="; //link
$limit = 3; //number of items you show in the paginator list



if ($_GET["page"])
{
$current = $_GET["page"];
}else{
$current = $_POST["page"];
}

$start = ($current-1) * $per_page;
$end = $start + $per_page;

//call to the paginator function ...
echo paginator ($current, $total, $per_page, $link, $limit);


//Show the results in different pages
for ($i = $start; $i<=$end ;$i++)
{
echo $myArray[$i]."<br />";
}


?>

//-------------------example.php----------------------------------------------------------------------------




2009/9/30 Angelo Zanetti <angelo@xxxxxxxxxxxxxxx>

>
> Hi All,
>
> I am looking for a paging script, not the normal type but slightly
> different. It must show as follows:
>
> 1 2 3 ... 12
>
> Then:
>
> 1 ... 678 ... 12
>
> And
>
> 1 ... 10 11 12
>
> I have googled and not really found much and don't really want to reinvent
> the wheel. I am sure I can write my own but due to time constraints ill
> like
> to get a script that will assist me.
>
> Thanks in advance
> http://www.wapit.co.za
> http://www.elemental.co.za
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
http://peachep.wordpress.com

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux