Hi everyone,
I have a set of links in my file with the following being an example of one of them:
<div> <?php echo "<a href=\"$url_business/index.php?subcatID=4&itemTypeID=3\">Security</a>"?></div>
When the above link is clicked, it captures the subcatID and the itemTypeID in a url string and then goes to the controller page index.php
In the controller page it checks to see if BOTH the subcatID and the itemTypeID are set and if so then selects items from the database based on the values, ie:
if (isset ($_GET['subcatID']) && ($_GET['itemTypeID'])) {
include_once(__ROOT__ . "/includes/db.inc.php");
$subcatID = mysqli_real_escape_string($link, $_GET['subcatID']);
$itemTypeID = mysqli_real_escape_string($link, $_GET['itemTypeID']);
$select = "SELECT
items.itemID,
itemTitle,
itemSKU,
itemDesc,
itemPrice,
itemColours,
itemTypes.itemType,
subcategories.subcategory,
sizesMen.size AS Msize,
sizesLadies.size AS Lsize,
itemImage";
$from = " FROM items
LEFT JOIN sizesMen ON sizesMen.sizeMenID=items.sizeMenID
LEFT JOIN sizesLadies ON sizesLadies.sizeLadiesID=items.sizeLadiesID
LEFT JOIN itemTypes ON itemTypes.itemTypeID=items.itemTypeID
LEFT JOIN item_to_subcat ON item_to_subcat.itemID = items.itemID
LEFT JOIN subcategories ON subcategories.subcatID = item_to_subcat.subcatID ";
$where = " WHERE itemTypes.itemTypeID='$itemTypeID' AND item_to_subcat.subcatID='$subcatID'";
The problem with this setup is that in some cases I want to be able to click on the link so that it just stores the subcatID and therefore the query would pull down the results based on if the item had that particular subcatID value, eg.
<div> <?php echo "<a href=\"$url_business/index.php?subcatID=4\">Security</a>"?></div>
But to do this I realise I have to revise the above controller code but I'm not sure how I'd do this since it would have to take into consideration the two situations. Some links would load based on both the subcatID AND the itemTypeID being present and others would load based only on the subcatID only being present.
Can anyone suggest how I'd do this?
Would really appreciate any advice.