By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,525 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,525 IT Pros & Developers. It's quick & easy.

How to use pagination with PHP and MySQL

P: 28
What this does is , take those results form the database and print them in tab like fashion. What I want to do is ,

1) Set a range , example 6
2) Display only 6 results after which I want "NEXT PAGE"
3) Again display 6 results with "PREVIOUS PAGE" and "NEXT PAGE"

I wanna add pagination to this. how can I do this?

Expand|Select|Wrap|Line Numbers
  1.             <?php
  2.               $count=0;
  3.             //$level = 4;
  4.             $levels_per_tier = 7;
  5.  
  6.             $tier = $_GET['tier'];
  7.             if(!$tier){$tier = 1;}
  8.  
  9.             $result = db_execute_return("Select MAX(level) from jobs;");
  10.             list($count_levels) = mysql_fetch_array($result);
  11.             $remin = $count_levels%7;
  12.             $count_ = $count_levels - $remin;
  13.             $count_ = $count_/7;
  14.             if($remin){$count_++;}
  15.             for($i=1;$i<=$count_;$i++){
  16.  
  17.                 $astart ="";$aend="";$cur="";
  18.                 if($i == $tier){$cur = "leveltier_clicked";}
  19.                 $start = ($i*7)-6;
  20.                 $res = db_execute_return("Select name from level where id= ".$start.";");
  21.                 list($levelname) = mysql_fetch_array($res);
  22.                 $end = ($i*7);
  23.                 if($end > $count_levels){$end = $count_levels;}
  24.                 if($level >= $start){
  25.                     $stat = $levelname;
  26.                     $astart = '<a href="?tier='.$i.'">';
  27.                     $aend = '</a>';
  28.                 }else{
  29.                     $stat = "LOCKED";
  30.                 }
  31.                 echo $astart ;
  32.  
  33. $lvldisp='Levels';
  34. $nxdisp=$start." - ".$end."<br/>".$stat;
  35.                 ?>
  36.                 <div class="leveltier <?= $cur;?>">
  37.                     <? echo $lvldisp.$nxdisp;?>
  38.                 </div>
  39.  
  40.                 <?php
  41.                 echo $aend ;
  42.             }
  43.  
Apr 23 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.