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.

有帮助吗?

解决方案 2

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' 

其他提示

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.

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top