By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 781 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

Multiple URL Variables

P: 3
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?BrandID=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?BrandID=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!
Jan 6 '08 #1
Share this Question
Share on Google+
3 Replies


shane3341436
P: 63
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?BrandID=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?BrandID=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
Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT * FROM products WHERE "; 
  2. if(isset($_GET['BrandID'])&&isset($_GET['CatID']))
  3. $sql .="BrandID = colname AND CatID = colname2";
  4. elseif(isset($_GET['BrandID']))
  5. $sql .="BrandID = colname";
  6. elseif(isset($_GET['CatID']))
  7. $sql .="CatID = colname2";
  8.  
  9.  
Jan 6 '08 #2

P: 3
I think this will solve ur problem
Expand|Select|Wrap|Line Numbers
  1. $sql="SELECT * FROM products WHERE "; 
  2. if(isset($_GET['BrandID'])&&isset($_GET['CatID']))
  3. $sql .="BrandID = colname AND CatID = colname2";
  4. elseif(isset($_GET['BrandID']))
  5. $sql .="BrandID = colname";
  6. elseif(isset($_GET['CatID']))
  7. $sql .="CatID = colname2";
  8.  
  9.  
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.
Jan 7 '08 #3

shane3341436
P: 63
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?
Jan 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.