Jump to content

Archived

This topic is now archived and is closed to further replies.

h8ids

Pagination of MySQL records

Recommended Posts

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]
<?php
session_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 buttons
echo "     <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 row
echo "<tbody id=\"offTblBdy\">";
for($c = 0; $c < $numofrows; $c++) {
$myrow = mysql_fetch_array($result); //get a row from our result set
if($c % 2) {
//this means if there is a remainder
echo "<TR class=\"alternateRow\">";
} else {
//if there isn't a remainder we will do the else
echo "<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 it
echo "</TABLE>\n";
// Close DB connection
mysql_close($db);
$Binary="0";
?>
[/code]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.