Multiple URL Variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SilverRain
    New Member
    • Jan 2008
    • 3

    Multiple URL Variables

    I am trying to do something fairly simple.

    I have two pages. Brands.php and Products.php.

    When I click on Brands.php it takes me to a list of Brands. I click on a brand, for example, brand1.php. From there I can choose a category - Category1.

    Category1 needs to go to store.php?Brand ID=1&CatID=1. At this point I have only got it to filter by either or... either BrandID or CatID. So I go to store.php?Brand ID=1, I get all items that are under Brand1, and similarly, when I go to CatID=1, I get all items that are under category1.

    The problem is that I cannot get it to filter by BrandID and CatID together. I need something of a combination of the AND/OR fuction in SQL.

    At this point here is what I have:

    SELECT *
    FROM products
    WHERE BrandID = colname OR CatID = colname2

    I have two variables defined: colname and colname2.

    Name: colname
    Type: Numeric
    Default value: -1
    Run-time Value: $_GET['BrandID']

    Name: colname2
    Type: Numeric
    Default value: -1
    Run-time Value: $_GET['CatID']


    This is successfully doing what I have described above, but I need it to filter by each one individually AND both together.

    I have tried:

    SELECT *
    FROM products
    WHERE (BrandID = colname OR CatID = colname2) OR (BrandID= colname AND CatID = colname2)

    but it did not succeed. Do I need to add a new colname3, perhaps?

    I am using Dreamweaver's Advanced Recordset.

    Your help and detailed answer will be greatly appreciated!

    Thanks!
  • shane3341436
    New Member
    • Mar 2007
    • 63

    #2
    Originally posted by SilverRain
    I am trying to do something fairly simple.

    I have two pages. Brands.php and Products.php.

    When I click on Brands.php it takes me to a list of Brands. I click on a brand, for example, brand1.php. From there I can choose a category - Category1.

    Category1 needs to go to store.php?Brand ID=1&CatID=1. At this point I have only got it to filter by either or... either BrandID or CatID. So I go to store.php?Brand ID=1, I get all items that are under Brand1, and similarly, when I go to CatID=1, I get all items that are under category1.

    The problem is that I cannot get it to filter by BrandID and CatID together. I need something of a combination of the AND/OR fuction in SQL.

    At this point here is what I have:

    SELECT *
    FROM products
    WHERE BrandID = colname OR CatID = colname2

    I have two variables defined: colname and colname2.

    Name: colname
    Type: Numeric
    Default value: -1
    Run-time Value: $_GET['BrandID']

    Name: colname2
    Type: Numeric
    Default value: -1
    Run-time Value: $_GET['CatID']


    This is successfully doing what I have described above, but I need it to filter by each one individually AND both together.

    I have tried:

    SELECT *
    FROM products
    WHERE (BrandID = colname OR CatID = colname2) OR (BrandID= colname AND CatID = colname2)

    but it did not succeed. Do I need to add a new colname3, perhaps?

    I am using Dreamweaver's Advanced Recordset.

    Your help and detailed answer will be greatly appreciated!

    Thanks!
    I think this will solve ur problem
    Code:
    $sql="SELECT * FROM products WHERE "; 
    if(isset($_GET['BrandID'])&&isset($_GET['CatID']))
    $sql .="BrandID = colname AND CatID = colname2";
    elseif(isset($_GET['BrandID']))
    $sql .="BrandID = colname";
    elseif(isset($_GET['CatID']))
    $sql .="CatID = colname2";

    Comment

    • SilverRain
      New Member
      • Jan 2008
      • 3

      #3
      Originally posted by shane3341436
      I think this will solve ur problem
      Code:
      $sql="SELECT * FROM products WHERE "; 
      if(isset($_GET['BrandID'])&&isset($_GET['CatID']))
      $sql .="BrandID = colname AND CatID = colname2";
      elseif(isset($_GET['BrandID']))
      $sql .="BrandID = colname";
      elseif(isset($_GET['CatID']))
      $sql .="CatID = colname2";
      Thanks for your response Shane.

      Could you please put this in the format that I used above. Forgive me, but I am still new to PHP/MySQL.

      If you could seperate the SQL from the PHP.

      For Example:

      SELECT *
      FROM products
      WHERE

      etc.

      Thank You again.

      Comment

      • shane3341436
        New Member
        • Mar 2007
        • 63

        #4
        Originally posted by SilverRain
        Thanks for your response Shane.

        Could you please put this in the format that I used above. Forgive me, but I am still new to PHP/MySQL.

        If you could seperate the SQL from the PHP.

        For Example:

        SELECT *
        FROM products
        WHERE

        etc.

        Thank You again.
        I'm confused with ur question. Aren't u using PHP ?
        Instead of using the whole SQL statement, u can use the variable $sql. isn't it?

        Comment

        Working...