I am coding an online store. I am using php4.2.2 and the xtemplate class so that my html code is separated from my php code. When I browse the online store I get 12 products on the first page. But the second page does not show up with a next link. I have an if else decision that prints a link if there is a previous or next page and does not print a link if there is not. It appears that my if statement may need help.
This is my previous next browser function.
function previousNextBrowser(&$xtpl, &$previousOffset, &$offset, &$nextOffset, &$ROWS, $row)
{
// Show the row numbers that are being viewed
$offsetLow = $offset + 1;
$offsetHigh = $rowCounter + $offset;
$xtpl->assign("offsetLow", $offsetLow);
$xtpl->assign("offsetHigh", $offsetHigh);
$xtpl->assign("rowsFound", $rowsFound);
// Are there any previous pages?
if ($offset > 0)
{
// Yes, so create a previous link
$previousUrl = rawurlencode($previousOffset);
$previous = Previous;
$offset1 = offset;
$xtpl->assign("scriptName", $scriptName);
$xtpl->assign("previousUrl", $previousUrl);
$xtpl->assign("browseString", $browseString);
$xtpl->assign("previous", $previous);
$xtpl->assign("offset", $offset1);
$xtpl->parse("main.pageBody.previousNextBrowser.previous");
}
// No, there is no previous page so don't
// print a link
else
{
$noPrevious = Previous;
$xtpl->assign("noPrevious", $noPrevious);
$xtpl->parse("main.pageBody.previousNextBrowser.noPrevious");
}
// Output the page numbers as links
// Count through the number of pages in the results
for($x=0, $page=1;
$x<$rowsFound;
$x+=$ROWS, $page++)
// Is this the current page?
if ($x < $offset || $x > ($offset + $ROWS - 1))
{
// No, so print out a link
$pageUrl = rawurlencode($x);
$xtpl->assign("scriptName", $scriptName);
$xtpl->assign("pageUrl", $pageUrl);
$xtpl->assign("browseString", $browseString);
$xtpl->assign("page", $page);
$xtpl->assign("offset", $offset1);
$xtpl->parse("main.pageBody.previousNextBrowser.page");
}
else
{
// Yes, so don't print a link
$xtpl->assign("curPage", $page);
$xtpl->parse("main.pageBody.previousNextBrowser.curPage");
}
// Are there any Next pages?
if ($rowsFound > $nextOffset)
{
// Yes, so create a next link
$nextUrl = rawurlencode($x);
$xtpl->assign("scriptName", $scriptName);
$xtpl->assign("nextUrl", $nextUrl);
$xtpl->assign("browseString", $browseString);
$xtpl->assign("next", $next);
$xtpl->assign("offset", $offset1);
$xtpl->parse("main.pageBody.previousNextBroser.next");
}
else
{
// No, there is no next page so don't
// print a link
$noNext = Next;
$xtpl->assign("noNext", $noNext);
$xtpl->parse("main.pageBody.previousNextBrowser.noNext");
}
$xtpl->parse("main.pageBody.previousNextBrowser");
}
This is the code where I parse the product information and call teh previous and next browser function.
$rowsFound = @ mysql_num_rows($products);
echo $rowsFound;
if ($rowsFound != 0)
{
// Yes, there is data.
// The "Previous" page begins at the current
// offset LESS the number of ROWS per page
$previousOffset = $offset - $ROWS;
// The "Next" page begins at the current offset
// PLUS the number of ROWS per page
$nextOffset = $offset + $ROWS;
// Seek to the current offset
if (!@ mysql_data_seek($products, $offset))
showerror();
// fetch the results of the query
// fetch the results of the query
for ( $rowCounter = 0;
(($rowCounter < $ROWS) &&
($row = @ mysql_fetch_array($products)) );
$rowCounter++)
{
// assign the variables to the blocks
// and parse the row blocks
$xtpl->assign("prodName", $row["product_name"]);
$xtpl->assign("prodPic", $row["product_pic"]);
$xtpl->assign("prodID", $row["product_id"]);
$xtpl->assign("regPrice", $row["product_cost"]);
$xtpl->assign("money", $money);
$xtpl->assign("cost", $cost);
if($row["product_sale"] > 0)
{
$xtpl->assign("sMoney", $sMoney);
$xtpl->assign("special", $special);
$xtpl->assign("specialPrice", $row["product_sale"]);
$xtpl->parse("main.pageBody.products.sDot");
}
$xtpl->assign("prodDesc", $row["product_desc"]);
$xtpl->assign("pCatName", $row["p_cat_name"]);
$xtpl->assign("sCatName", $row["s_cat_name"]);
if (!empty($row["s_cat_name"]))
$xtpl->parse("main.pageBody.products.sCatDot");
$xtpl->assign("tCatName", $row["t_cat_name"]);
if (!empty($row["t_cat_name"]))
$xtpl->parse("main.pageBody.products.tCatDot");
$xtpl->parse("main.pageBody.products");
}
previousNextBrowser(&$xtpl, &$previousOffset, &$offset, &$nextOffset, &$ROWS, $row);
}
else
$rowsFound = "No products found matching your criteria.";