473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use pagination with PHP and MySQL

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
0 1118

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

Similar topics

2
by: Somerset Bob | last post by:
I've got pagination errors in a phpBB board. Some forums are showing "page 1 of 0". Previous enquiries both here and at the phpBB forum have given me half-answers, the latest of which contained...
5
by: leegold2 | last post by:
Hi, I have been looking around for a way to paginate php/mysql table output. There are a lot of hits when I google it. But unfortunately what I have tried either does not work or is imho just...
9
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
10
by: EOZyo | last post by:
Hi, i'm trying to set pagination for a search i run on my website, i'll try to explain the easiest i can: When i click the search button on search.php, data is received and stored in variables...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
1
exoskeleton
by: exoskeleton | last post by:
Hi guys...need help here ... My problem is about pagination like <<PREV 1,2,3,4,5,6 NEXT>> Does LIMIT Function applicable in PostgreSQL? $SQL="SELECT * FROM TABLE1 LIMIT 0,5"; the sql above...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.