Adjustment of WHERE clause needed

Hi everyone,

The following line of code checks to see if BOTH the subcatID and the itemTypeID are set:

if (isset ($_GET['subcatID']) && ($_GET['itemTypeID'])) {

Then the values in these two variables are used in the following line of SQL:

WHERE itemTypes.itemTypeID='$itemTypeID' AND item_to_subcat.subcatID='$subcatID'";

I need to revise the first line so that it’s:

if (isset (($_GET['subcatID']) && ($_GET['itemTypeID'])) || ($_GET['subcatID'])) {

The above would allow for two options, ie. both the subcatID AND itemTypeID being set but also will allow for a scenario where just the subcatID is set. Therefore I need to revise the WHERE clause above to allow for these two scenarios.

I wondered if someone could advise me how to do this?

Appreciate any assistance.


if (isset (($_GET['subcatID']) && ($_GET['itemTypeID'])) || ($_GET['subcatID'])) {
	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, 
            itemSKULadies, 
            itemSKUMen, 
            itemDescLadies, 
            itemDescMen,  
            itemPriceBoth,
            itemPriceFemale,
            itemPriceMale,
            itemColoursBoth,
            itemColoursFemale,
            itemColoursMale,
            itemTypes.itemType,
			subcategories.subcategory,
            sizesMen.size AS Msize, 
            sizesLadies.size AS Lsize, 
            itemSwatchBoth,
            itemSwatchFemale,
            itemSwatchMale,
            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'";

Seems I’ve worked this out guys:

	$where 	= " WHERE item_to_subcat.subcatID='$subcatID'";
	if (isset ($_GET['itemTypeID'])) {
        $where = $where . " AND itemTypes.itemTypeID='$itemTypeID'";
    }

False alarm - thanks.