Jump to content


Photo

Pagination of MySQL records


  • Please log in to reply
4 replies to this topic

#1 h8ids

h8ids
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 31 May 2006 - 08:47 PM

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:
<?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";
?>

"Macromedia Flash will never be anything more than a cartoon creation tool." - Someone I know.

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 31 May 2006 - 09:40 PM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 h8ids

h8ids
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 01 June 2006 - 09:01 PM

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) View Post[/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]

"Macromedia Flash will never be anything more than a cartoon creation tool." - Someone I know.

#4 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 06 June 2006 - 08:06 PM

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?
Roy Simkes
Yet Another Parkyeri Developer

#5 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 06 June 2006 - 09:56 PM

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.

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users