Reputation: 22879
I'm using PHP and SQL to create a stats summary based on weekly periods.
I initially thought all the items would have the same date and the code below worked in that situation.
$result1 = mysql_query("SELECT * FROM phoneappdetail WHERE salebarn = 'OSI' AND saledate = '2012-06-6' ORDER BY wtcode ");
However now I've found out that the items I need to query have varying days.
How can I change my query to get dates between 2012-06-6 and 2012-06-12 instead of only dates exactly on 2012-06-6?
Upvotes: 0
Views: 68
Reputation: 1636
$result1 = mysql_query("SELECT * FROM phoneappdetail WHERE salebarn = 'OSI' AND saledate > '2012-06-6' AND saledate < '2012-06-12' ORDER BY wtcode ");
Upvotes: 0
Reputation: 27594
Use SQL BETWEEN clause:
SELECT * FROM phoneappdetail WHERE salebarn = 'OSI' AND (saledate BETWEEN '2012-06-6' AND '2012-06-12') ORDER BY wtcode
Upvotes: 3