473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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?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
3 2354
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
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
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

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

Similar topics

13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
10
by: Johnny Lin | last post by:
Hi! Is there a way to automate the unbinding of multiple variables? Say I have a list of the names of all variables in the current scope via dir(). Is there a command using del or something...
1
by: DrewM | last post by:
I'm still thinking about session variables :-) Does anyone know the detail of how session variables are actually stored? The question I'm trying to answer is: Is it more efficient to store and...
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
9
by: lbj137 | last post by:
I have two files: A.c and B.c. In both files I define a global variable, int xxxx; When I compile with a green hills compiler (and also i think with a GNU compiler) I get no errors or warnings....
3
by: Carl Johansen | last post by:
I have a big ASP website (used by several thousand car dealers) that is a collection of lots of small and medium-sized applications. Now I want to start adding ASP.NET applications to it. I have...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
6
by: Gaijinco | last post by:
I'm having a weird error compiling a multiple file project: I have three files: tortuga.h where I have declared 5 global variables and prototypes for some functions. tortuga.cpp where I...
2
by: Immortal Nephi | last post by:
You may have heard diamond shape. You create one base class. One base class has member functions and member variables. You create two derived classes. All member functions and member variables...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.