View Single Post
Old 09-05-2005, 11:20 AM   #2 (permalink)
sandman
Junior Member
 
Join Date: Jul 2005
Posts: 36
Default

Hi,

There are several ways to accomplish this. Here is some code you may modify to fit your own site:
PHP Code:
<? 
//REMEMBER TO CONNECT TO DATABASE! 

//**EDIT TO YOUR TABLE NAME, ECT. 

$t mysql_query("SELECT * FROM `table` WHERE `cat` = '".addslashes($_GET['cat'])."'"); 
  if(!
$t) die(mysql_error()); 
    
$a                  mysql_fetch_object($t); 
$total_items      mysql_num_rows($t); 
$limit            $_GET['limit']; 
$type             $_GET['type']; 
$page             $_GET['page']; 

//set default if: $limit is empty, non numerical, less than 10, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit 10) || ($limit 50)) { 
     
$limit 10//default 

//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page 0) || ($page $total_items)) { 
      
$page 1//default 


//calcuate total pages 
$total_pages     ceil($total_items $limit); 
$set_limit          $page $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q mysql_query("SELECT * FROM `table` WHERE `cat` = '".addslashes($_GET['cat'])."' LIMIT $set_limit, $limit"); 
  if(!
$q) die(mysql_error()); 
     
$err mysql_num_rows($q); 
       if(
$err == 0) die("No matches met your criteria."); 

//Results per page: **EDIT LINK PATH** 
echo("   
<a href=www.yoursite.com/stuff/script.php?cat=$cat&amp;limit=10&amp;page=1>10</a> | 
<a href=www.yoursite.com/stuff/script.php?cat=$cat&amp;limit=25&amp;page=1>25</a> | 
<a href=www.yoursite.com/stuff/script.php?cat=$cat&amp;limit=50&amp;page=1>50</a>"
); 

//show data matching query: 
while($code mysql_fetch_object($q)) { 
     echo(
"item: ".results->title."<BR>"); 


$cat urlencode($cat); //makes browser friendly 

//prev. page: **EDIT LINK PATH** 

$prev_page $page 1

if(
$prev_page >= 1) { 
  echo(
"<b>&lt;&lt;</b> <a href=http://www.yoursite.com/stuff/script.php?cat=$cat&amp;limit=$limit&amp;page=$prev_page><b>Prev.</b></a>"); 


//Display middle pages: **EDIT LINK PATH** 

for($a 1$a <= $total_pages$a++) 

   if(
$a == $page) { 
      echo(
"<b> $a</b> | "); //no link 
     
} else { 
  echo(
"  <a href=http://www.yoursite.com/stuff/script.php?cat=$cat&amp;limit=$limit&amp;page=$a> $a </a> | "); 
     } 


//next page: **EDIT THIS LINK PATH** 

$next_page $page 1
if(
$next_page <= $total_pages) { 
   echo(
"<a href=http://www.yoursite.com/stuff/script.php?cat=$cat&amp;limit=$limit&amp;page=$next_page><b>Next</b></a> &gt; &gt;"); 


//all done 
?>

Enjoy
sandman is offline   Reply With Quote
Sponsored Links