*EDIT-FIXED!* Pepple having trouble with pagination could just copy this and place in their own values. ( i am not taking credit for this script though) Im only taking credit for tihs part:
Code: Select all
$num=mysql_numrows($result);
$lo=0;
while ($lo < $num) {
$SomeVariable1=mysql_result($result,$lo,"SomeField1");
$SomeVariable2=mysql_result($result,$lo,"SomeField2");
echo "<b>$SomeVariable1</b><br><br>$SomeVariable2<br><br>";
++$lo;Code: Select all
<?php
class Pager
{
function getPagerData($numHits, $limit, $page)
{
$numHits = (int) $numHits;
$limit = max((int) $limit, 1);
$page = (int) $page;
$numPages = ceil($numHits / $limit);
$page = max($page, 1);
$page = min($page, $numPages);
$offset = ($page - 1) * $limit;
$ret = new stdClass;
$ret->offset = $offset;
$ret->limit = $limit;
$ret->numPages = $numPages;
$ret->page = $page;
return $ret;
}
}
?>
<?php
// get the pager input values
$page = $_GET['page'];
$limit = 10; // Change to number of rows you want displayed in each page.
$result = mysql_query("select count(*) from YourTable"); // Change YourTable to the table in MySQL you want to get your data from.
$total = mysql_result($result, 0, 0);
// work out the pager values
$pager = Pager::getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;
// use pager values to fetch data
$query = "select * from YourTable order by SomeField limit $offset, $limit"; //Change YourTable like u did above. Chagne SomeField to which ever Column in MySQL you want to order the rows by alphabetically.
$result = mysql_query($query);
// use $result here to output page content
$num=mysql_numrows($result);
$lo=0;
while ($lo < $num) {
$SomeVariable1=mysql_result($result,$lo,"SomeField"); // Replace $SomeVariable with anything. Than you may echo it below. Replace SomeField with first column u want to display from MySQL
$SomeVariable2=mysql_result($result,$lo,"SomeField"); //Same as above but change SomeField to the second Column in MySQL you want to display.
echo "<b>$SomeVariable1</b><br><br>$SomeVariable2<br><br>"; //Replace with your variables from above.
++$lo;
}
?>
<?
// output paging system (could also do it before we output the page content)
if ($page == 1) // this is the first page - there is no previous page
echo "Previous";
else // not the first page, link to the previous page
echo "<a href="ThisScript.php?page=" . ($page - 1) . "">Previous</a>"; //Just put the url to this script but include the ?page=
for ($i = 1; $i <= $pager->numPages; $i++) {
echo " | ";
if ($i == $pager->page)
echo "Page $i";
else
echo "<a href="ThisScript.php?page=$i">Page $i</a>"; //Just put the url to this script and add ?page=$i. ($i gets the page number)
}
if ($page == $pager->numPages) // this is the last page - there is no next page
echo "Next";
else // not the last page, link to the next page
echo "<a href="ThisScript.php?page=" . ($page + 1) . "">Next</a>"; //Just put the url to this script but include the ?page=
?>