So the query at the top finds all the relevant products, and then GROUPs then by ID to avoid duplicates (as there will be because it's looking for the TAGS in two database tables. However.....
Code: Select all
$query = ("SELECT p.datebackinstock, p.datepricedrop, p.id, p.catid, p.subid, p.catname, p.subname, p.title, p.price, p.photoprimary, p.comingsoon, p.rcstock, p.preorder, p.bundleroman1, p.bundleroman2, p.bundleroman3, p.bundleroman4, p.bundleroman5, p.pricedrop FROM products AS p
LEFT JOIN producttags AS t ON p.id = t.prodid
LEFT JOIN subcategorytags AS s ON p.subid = s.subid
WHERE t.producttag =:producttag OR s.tag =:producttag AND p.pause = 'off' GROUP BY p.id ORDER BY rcstock = 'in stock' DESC, rcstock = '' DESC, comingsoon = 'yes', rcstock = 'out of stock', $order LIMIT $offset, $rowsPerPage");So how do I do the page numbering at the bottom using this query, effectively?
Code: Select all
$query = "SELECT COUNT(p.id) AS numrows FROM products AS p
LEFT JOIN producttags AS t ON p.id = t.prodid
LEFT JOIN subcategorytags AS s ON p.subid = s.subid
WHERE (t.producttag =:producttag OR s.tag =:producttag) AND p.pause = 'off'";
$result = $pdo->prepare($query);
$result->execute(array(':producttag' => $producttag));
$numrows = $result->fetchColumn();
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pagenum)
{
$nav .= " <div class='pagelinkactive'>$page</div> "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"/product-tags/page/$page/$producttagDash/\" class='pagelink'>$page</a>";
}
}