I need to do a few things here and I’m confused on how this should work.
Here are the variables I need to work with:
Date Range
Employee ID
Team
and a possible additional search term (acct_number=’$_REQUEST[q]’) if someone wants to search for a specific account number.
Each variable is populated with a drop down select, the first option being * for all records. The dates are set using a date picker, calendar style, and it’s automatically set as date 1=seven days ago and date 2=today.
My query:
SELECT * FROM table
WHERE job_date BETWEEN '$search_date1' AND '$search_date2' AND
employee_id='$searched_employee' AND team='$searched_team' AND
acct_number='$_REQUEST[q]'
ORDER BY employee_id desc
I know the records are there but my search still returns no records. After the date, the AND employee_id=’$searched_employee’ could be * so it should return all records and the same goes for the team.
Echoing the variables to try make sure something was set gives me this:
No records found for “Employee” for dates between 2011-05-01 and 2011-05-31 and on team “Team”.
Can I not request more with AND in the Select statement after I use the BETWEEN?
Thanks in advance!
–Joel
You cannot use ‘*’ wildcard for WHERE clause.
Try using variables for conditions you put in your query, like:
and put
$employee_condinside your query instead ofAND employee_id='$searched_employee'.Repeat for every condition you need.