SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adjustment of WHERE clause needed

    Hi everyone,

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


    PHP Code:
    if (isset ($_GET['subcatID']) && ($_GET['itemTypeID'])) { 
    Then the values in these two variables are used in the following line of SQL:

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

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

    PHP Code:
    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.


    PHP Code:
    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'"

  2. #2
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems I've worked this out guys:

    PHP Code:
        $where     " WHERE item_to_subcat.subcatID='$subcatID'";
        if (isset (
    $_GET['itemTypeID'])) {
            
    $where $where " AND itemTypes.itemTypeID='$itemTypeID'";
        } 
    False alarm - thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •