Hi there,
Im having some troubles with the subcategory pagination, im using as example the plaincart from http://www.phpwebcommerce.com/shop-admin-view-product.php and everithing works fine expect this, at the moment... When im on the category list the pagination works fine but once i insert one subcategory, the pagination sends me back to categories !! I tried everithing, with cat_parent_id, child ... But no sucess :queasy:
Here is some of the category code:
if (isset($_GET['catId']) && (int)$_GET['catId'] >= 0) {
$catId = (int)$_GET['catId'];
$queryString = "&catId=$catId";
} else {
$catId = 0;
$queryString = '';
}
// for paging
// how many rows to show per page
$rowsPerPage = 5;
$sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image
FROM tbl_category
WHERE cat_parent_id = $catId
ORDER BY cat_name";
$result = dbQuery(getPagingQuery($sql, $rowsPerPage));
$pagingLink = getPagingLink($sql, $rowsPerPage);
$cat_parent_id = 0;
if (dbNumRows($result) > 0) {
$i = 0;
while($row = dbFetchAssoc($result)) {
extract($row);
if ($i%2) {
$class = 'row1';
} else {
$class = 'row2';
}
$i += 1;
if ($cat_parent_id == 0) {
$cat_name = "<a href=\"index.php?catId=$cat_id\">$cat_name</a>";
}
if ($cat_image) {
$cat_image = WEB_ROOT . 'images/category/' . $cat_image;
} else {
$cat_image = WEB_ROOT . 'images/no-image-small.png';
}
And the pagination:
function getPagingQuery($sql, $itemPerPage = 5)
{
if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
$page = (int)$_GET['page'];
} else {
$page = 1;
}
// start fetching from this row number
$offset = ($page - 1) * $itemPerPage;
return $sql . " LIMIT $offset, $itemPerPage";
}
function getPagingLink($sql, $itemPerPage = 5, $strGet = '')
{
$result = dbQuery($sql);
$pagingLink = '';
$totalResults = dbNumRows($result);
$totalPages = ceil($totalResults / $itemPerPage);
// how many link pages to show
$numLinks = 5;
// create the paging links only if we have more than one page of results
if ($totalPages > 1) {
$self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
if (isset($_GET['page']) && (int)$_GET['page'] > 0) {
$pageNumber = (int)$_GET['page'];
} else {
$pageNumber = 1;
}
// print 'previous' link only if we're not
// on page one
if ($pageNumber > 1) {
$page = $pageNumber - 1;
if ($page > 1) {
$prev = " <a href=\"$self?page=$page&$strGet/\">[Prev]</a> ";
} else {
$prev = " <a href=\"$self?$strGet\">[Prev]</a> ";
}
$first = " <a href=\"$self?$strGet\">[First]</a> ";
} else {
$prev = ''; // we're on page one, don't show 'previous' link
$first = ''; // nor 'first page' link
}
// print 'next' link only if we're not
// on the last page
if ($pageNumber < $totalPages) {
$page = $pageNumber + 1;
$next = " <a href=\"$self?page=$page&$strGet\">[Next]</a> ";
$last = " <a href=\"$self?page=$totalPages&$strGet\">[Last]</a> ";
} else {
$next = ''; // we're on the last page, don't show 'next' link
$last = ''; // nor 'last page' link
}
$start = $pageNumber - ($pageNumber % $numLinks) + 1;
$end = $start + $numLinks - 1;
$end = min($totalPages, $end);
$pagingLink = array();
for($page = $start; $page <= $end; $page++) {
if ($page == $pageNumber) {
$pagingLink[] = " $page "; // no need to create a link to current page
} else {
if ($page == 1) {
$pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";
} else {
$pagingLink[] = " <a href=\"$self?page=$page&$strGet\">$page</a> ";
}
}
}
$pagingLink = implode(' | ', $pagingLink);
// return the page navigation link
$pagingLink = $first . $prev . $pagingLink . $next . $last;
}
return $pagingLink;
}
I think the error comes from the line
$cat_name = "<a href=\"index.php?catId=$cat_id\">$cat_name</a>";
But im to newb to work it out
Thnks in advance 😉