Hello,
I have been struggling in making this script work but no luck… I searched many PHP forums, googled as well… but didnt find what I need T_T
Simply is, I need to limit my search results like this 1-10 then 11-20 … whenever the user click on 1-10, the pages links 1,2,3 etc will appear at the buttom… now my sctipt outputs the 1,2,3 pages …and I have MANY results… limiting them into sets will be proper
Note: $x is a string of values;
Here’s the script:
$page = $_GET['page'];
$limit = 10;
$result = mysql_query("select count(*) from $table $x;");
$total = mysql_result($result, 0, 0);
$pager = Pager::getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;
$sql = mysql_query("SELECT * FROM $table $x LIMIT $offset, $limit");
$number1 = mysql_numrows($sql);
if ($number1 == 0){ echo "<font face=verdana size=1 color=red><br><center>No Matchs Found";
exit(); }
else {
echo "<font face=verdana size=1><b><u>Search Results:</u></b><br><br>";
while($row=mysql_fetch_array($sql)) {
echo "Date:</b>".$row['date'];
echo "<br>";
echo "<b>Report #: </b>".$row['report'];
echo "<br>";
echo "<b>Name: </b>".$row['name'];
echo "<br>";
}
}
echo "<br>";
if ($page == 1)
echo "Previous ";
else
echo "<a href=\"$PHP_SELF?page=" . ($page - 1) .\"> Previous </a>";
for ($i = 1; $i <= $pager->numPages; $i++) {
echo " | ";
if ($i == $pager->page)
echo "Page $i";
else
echo "<a href=\"$PHP_SELF?page=$i\"> Page $i </a>";
}
if ($page == $pager->numPages)
echo " | Next ";
else
echo " | <a href=\"$PHP_SELF?page=" . ($page + 1) . "\"> Next </a>";
//I got this Class from a paging tutorial >_>
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;
}
}
Thank you so much for your help T_T
OniHime