h8ids Posted May 31, 2006 Share Posted May 31, 2006 Attempting to set up pagination.Data is being passed to page and being displayed in a dynamic table (Adjusts based upon the number of records to display.).Table row colors alternate; gray - white - gray.In addition, the <thead> is set up to allow for ordering of records.Now I want to add pagination; limiting the number of displayed rows to 20.Needing a good tutorial.Here's what I have so far:[code]<?phpsession_start;error_reporting(E_ALL | 'E_STRICT');$db = mysql_connect("localhost", "root", ""); mysql_select_db("newcourse",$db);$result = mysql_query("SELECT * FROM proposals ORDER by Records DESC",$db);//let's get the number of rows in our result so we can use it in a for loop$numofrows = mysql_num_rows($result);//Table formatting and sorting buttonsecho " <b>Courses you have submitted.</b><TABLE BORDER=0 width='631' cellpadding=4 cellspacing=0 bgcolor='#FFFFFF'><thead bgcolor='lightyellow'><TR><TH><a title=\"Organize by course name\" href=\"\" onclick=\"this.blur(); return sortTable('offTblBdy', 0, true);\"><B>Course title</B></a></TH><TH><a title=\"Organize by course number\" href=\"\" onclick=\"this.blur(); return sortTable('offTblBdy', 1, true);\"><B>Course number</B></a></TH><TH></TH></TR></thead><TFOOT><TR bgcolor='lightyellow'><Td><img src='spacer.jpg'></Td><Td><img src='spacer.jpg'></Td><Td><img src='spacer.jpg'></Td></Tr></TFOOT>";// coloring every other rowecho "<tbody id=\"offTblBdy\">";for($c = 0; $c < $numofrows; $c++) {$myrow = mysql_fetch_array($result); //get a row from our result setif($c % 2) { //this means if there is a remainderecho "<TR class=\"alternateRow\">";} else { //if there isn't a remainder we will do the elseecho "<TR>";}echo "<TD>".$myrow['CourseTitle']."</TD> <TD><center>".$myrow['CourseNumber']."</center></TD>";echo "<TD width='170'><a title='Edit record' style='text-decoration: none' href=\"addedit.php?Records=".$myrow['Records']."\">Edit</a> |<a title='Create PDF' style='text-decoration: none' href=\"PDFgen.php?Records=".$myrow['Records']."\">PDF </a> |<a title='Submit for review' style='text-decoration: none' href=\"EmailComment.php?Records=".$myrow['Records']."\">Submit </a> |<a title='Delete record' style='text-decoration: none' href=\"delete.php?Records=".$myrow['Records']."\"> Delete</a>";//<a onmousedown='textSWAP()' id='textSubmitted' style='text-decoration: none' href=\"javascript: textSWAP('textSubmitted','Submitted');\">Submit </a> |echo "</TD>";echo "</TR>";}echo "</tbody>";//now let's close the table and be done with itecho "</TABLE>\n";// Close DB connectionmysql_close($db);$Binary="0";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10898-pagination-of-mysql-records/ Share on other sites More sharing options...
litebearer Posted May 31, 2006 Share Posted May 31, 2006 right here in rivercity[a href=\"http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorial_cat/25/P...-Pagination.php[/a]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/10898-pagination-of-mysql-records/#findComment-40710 Share on other sites More sharing options...
h8ids Posted June 1, 2006 Author Share Posted June 1, 2006 Thanks litebearer,I'll check it out.[!--quoteo(post=378860:date=May 31 2006, 04:40 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 31 2006, 04:40 PM) [snapback]378860[/snapback][/div][div class=\'quotemain\'][!--quotec--]right here in rivercity[a href=\"http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php\" target=\"_blank\"]http://www.phpfreaks.com/tutorial_cat/25/P...-Pagination.php[/a]Lite...[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/10898-pagination-of-mysql-records/#findComment-41018 Share on other sites More sharing options...
radalin Posted June 6, 2006 Share Posted June 6, 2006 Well it's easy if we have static search parameters. What if I'm taking data from o form with post method? If I try to make a link then I loose the post data. I have tried to link to PHP_SELF but seems to fail. So what should I do if i get data from a form via post method and if i want to make a pagination to it? Quote Link to comment https://forums.phpfreaks.com/topic/10898-pagination-of-mysql-records/#findComment-42568 Share on other sites More sharing options...
nogray Posted June 6, 2006 Share Posted June 6, 2006 you can always use a $_REQUEST instead of $_POST or $_GET. $REQUEST will work for both. Or you can always alter the links to submit a form using javascript to fill in the start, dis and the search term. Quote Link to comment https://forums.phpfreaks.com/topic/10898-pagination-of-mysql-records/#findComment-42608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.