Filter Recordset by More Than One Field
I have an index page with a dynamic drop-down menu where you select the state. Then you hit submit and it goes to my results page where a dynamic table displays all record from my table with the selected state. This works perfectly.
Now, I want to add a second field to filter the recordset: year. The user shoul dbe able to select the state (ex: CA) and the year (ex:2006), hit submit and get their results. I just can't figure out how to get this to work.
On the index page, I added the second drop-down menu and have it displaying the distinct year values.
On the results page, I opened the recordset that the results are coming from. This was the code for just the first filter field:
SELECT *
FROM fiber_intake
WHERE `State` = colname
This worked just fine. The variable colname had this info associated with it:
Name: colname
Type: Text
Default value: -1
Run-time Value: $_GET['state']
I tried to write add the code for the second field, but I'm obviously doing in wrong (I'm not too familiar with MySQL):
SELECT *
FROM fiber_intake
WHERE `State` = colname AND WHERE `Year` = colname2
I had defined a second variable colname2, even though I'm not sure if I was supposed to. Here's the info associated with colname2:
Name: colname2
Type: Numeric
Default value: -1
Run-time Value: $_GET['year']
When I viewed this in the browser my index page appears with my drop-down menus. I selected a year and hit submit. This is the error code I got:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `Year` = 2006 LIMIT 0, 10' at line 1
Can anyone help me out?
Thanks!
