Search code examples
phpmysqldate-rangemysql-num-rows

PHP MYSQL select * with this value with between these dates


I'm trying to select a list of customers that have entered a specific voucher code, within certain dates.

Here is my code with my latest attempt:

$result = mysql_query(
          "SELECT COUNT(members.voucher_code)
           FROM members WHERE YEAR(date_started) = 2014
           members.voucher_code = 'new'");
$count = mysql_result($result, 0);
echo $count;

I would like it to show all voucher codes that have the value of new which have been submitted between 01/01/14 - 31/12/14

I've tried a number of things but I can't seem to get it working correctly.


Solution

  • Try this :

    SELECT COUNT(members.voucher_code) 
    FROM members 
    WHERE 
       members.voucher_code = 'new' AND
       date_started BETWEEN '2014-01-01' AND '2014-12-31'