You Are Here: Home »   Code Friday September 3rd 2010

Code Library - php

Multiple Page Lists - (1779 views)


<?

//count the total entries
//this is just an example, you need to add your own query + field data
$total "SELECT COUNT(*) FROM table";
$result mysql_query($total);
$count mysql_result($result,0);

    
//if $list != specified display first page
    
if(!isset($list) || $list 0) {
       
$list 0;
  }
       
//set total to show per page
       
$show 15;
       
$start $list $show;

//round up the fraction to a $list #
    
if($start $count) {
       
$list ceil($count $show);
  }
    else
  {
//do your query adding LIMIT $start,$show
//this is just an example, you need to add your own query + field data
$query mysql_query("SELECT * FROM table LIMIT $start,$show");
     }
     
//show results here
     
while ($r mysql_fetch_array ($query)) {
     echo 
"$r[data]\n";
  }
//display navigation
if($list 0)
     {
     
//previous page link
     
$prev $list 1;
     echo 
"<a href='$PHP_SELF?list=$prev'>&#60;&#60; Prev</a>&nbsp;";
  }
if(
$start $show $count)
     {
     
//next page link
     
$next $list 1;
     echo 
"<a href='$PHP_SELF?list=$next'>Next &#62;&#62;</a>";
   }

?>