0

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.

Linga
  • 10,379
  • 10
  • 52
  • 104
Connor
  • 3
  • 3

3 Answers3

2

Correct query should be like:

SELECT COUNT(members.voucher_code)
FROM members
WHERE date_started > 'from_date' AND date_started < 'to_date'

Here from_date and to_date is the date passed by you.

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
Manish Kumar
  • 571
  • 3
  • 15
1

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' 
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
0

You may try:

$result = mysql_query("SELECT COUNT(members.voucher_code)
FROM members
WHERE YEAR(date_started) = 2014 and members.voucher_code = 'new'");

You are missing the AND condition in your query.

Linga
  • 10,379
  • 10
  • 52
  • 104
Vivek Jain
  • 3,811
  • 6
  • 30
  • 47