mona Posted September 4, 2006 Share Posted September 4, 2006 Iam doing a project using php and mysql, in my project I had a list of students' information saved in a database, Iam trying to put all the information in html table, so I got the data from database and display them in an html table. the problem is that the data is too large and I want to divide it into more than one page where each page has about 10 students. and on clicking next the other page comes.how can I do that in php, I don't need a code I need the way to do that, that is under the next button or link where should I submit the page number or etc.. and can i do them all on the same php file. Link to comment Share on other sites More sharing options...
SFB Posted September 4, 2006 Share Posted September 4, 2006 try something like this. your url would be something like /index.php?page=1 then php would multiply that by ten to get where to start with and then add 10 to find what row to end with. if the page was 0 it would be 0-10 and if it was 1 it would be 10-20 and so on. a link would be placed at the end so the user could go to the next ten pages. I did not include a way to check and see if the rows exsist in the database. that is up to you. <?phpif(isset($_GET['page']){ $page = $_GET['page']; //the math to figure out what row to start on $min = $page * 10; //the math to figure out what row to end on $max = $page * 10; $max +=10; //next page $next = $page++;}else{//if no page is set start a 0 and go to 10 $min = "0"; $max = "10"; $next = "1";}//loop from starting row to end rowfor($i=$min; $i>$max; $i++){//database stuff goes here $i will be the row number}echo"<a href='/index.php?$next'>Next ten</a>";?> Link to comment Share on other sites More sharing options...
tutsamewasa Posted September 5, 2006 Share Posted September 5, 2006 Hi,For pagination use the Limit option in your query and show only number of records that you want to display on one page. Keep a track of the start id and end id for the current page and use that to buld your query again with limit for next or previous page.Hope this helps.Good LuckHemendra Singh ShaktawatMindfire Solutionswww.mindfiresolutions.com Link to comment Share on other sites More sharing options...
ramanjaneyulu Posted September 5, 2006 Share Posted September 5, 2006 Logic behind Pagination#START PAGINATION#$RowCount is total no of records$Limit = 25;$Pagination = true;$StartRows = $_GET["StartRows"];$Total_Pages = ceil($RowCount / $Limit); $Modulus = $RowCount % $Limit;$LastRows = ($Total_Pages*$Limit) - 2*($Modulus) -1;if (!isset($StartRows)){ //Default to this: $StartRows = 0 ; $EndRows = $StartRows + $Limit; $Current_Pages_No = $Total_Pages - ceil(($RowCount-$EndRows -1) / $Limit); $Previous = $StartRows; if($EndRows > $RowCount) { $EndRows = $RowCount; $Current_Pages_No = $Total_Pages - ceil(($RowCount-$EndRows -1) / $Limit); $Previous = $EndRows; $Pagination = false; } }else{ $EndRows = $StartRows + $Limit; $Current_Pages_No = $Total_Pages - ceil(($RowCount-$EndRows -1) / $Limit); $Previous = $Current_Pages_No*$Limit - 2*$Limit; if($EndRows > $RowCount) { $EndRows = $RowCount; $Current_Pages_No = $Total_Pages - ceil(($RowCount-$EndRows -1) / $Limit); $Previous = ($Current_Pages_No-2)*$Limit; } }$No_Pages = "<div align= 'right'> ".($StartRows + 1)." - ".$EndRows." of about ". $RowCount." </div>";print "$No_Pages" ;#END PAGINATION Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now