Hi there!
I finally managed to do paging BUT it works only when i manually give 'category' a value.
If i use $_POST[category] a warning occurs and no result is posted:
Warning: Invalid argument supplied for foreach() in
C:...\a.php on line 71
Here is my code in the a.php file:
<?php include("header.php"); php?>
<?php
require_once 'Pager.php';
$db = DB::connect('mysql://root:@localhost/db');
$sql = "SELECT title,year
FROM document AS doc
WHERE year between 1995 and 2005
AND category='$_POST[category]'";
// Find our starting Row
$from = $_GET;
if (!is_numeric($from)){
$from = 0; }
// We'll limit the rows to 10 per page
$limit = 2;
// Get the total number of rows and build our pager
$nrows =& $db->getRow('SELECT count(*)
FROM document AS doc
WHERE year between 1995 AND 2005
AND category='$_POST');
$data = DB_Pager::getData($from, $limit, $nrows[0]);
// Grab 2 rows using PEAR:B limitQuery function
$res = $db->limitQuery($sql, $from, $limit);
// Display the rows
print("<p><HR width=100% size=4 noshade><p>");
// Build our pager
echo $data . ' Results found -- ';
echo 'displaying '. $data . ' results per page<br><br>';
// Create a header showing which page we're on
echo '<h4> Page '. $data . ' of ' . $data . '</h4>';
print("<p><TABLE border=1>\n");
print("<TR><TD><center><b>year</b></center></TD>
<TD><b><center>title</center></b>
</TR>");
while ($row = $res->fetchRow()) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
print("<TD>$row[2]</TD>");
print("<TD>$row[1]</TD>");
}
print("</TR></TABLE><p>");
//echo "Jump to page: ";
// Unless we're on the first page, show a link to the previous page
if ($data != $data){
echo '<a href="'. "$PHP_SELF?from=" . $data .'"><< Prev </a>';
}
// Direct link to pages
foreach ($data as $page => $start_row) {
echo "[ <a href='$PHP_SELF?from=$start_row'>$page</a> ] ";
}
// Unless we're on the last page, show a link to the next page
if ($data != $data){
echo '<a href="'. "$PHP_SELF?from=" . $data . '">Next>> </a>';
}
?>
<?php include("footer.php"); php?>
Thanks for your time.
Cali