简体   繁体   English

PHP MYSQL在这些日期之间选择带有此值的*

[英]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 . 我正在尝试选择在特定dates内输入特定voucher codecustomers列表。

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 我希望显示所有between 01/01/14 - 31/12/14提交的具有new值的凭证代码

I've tried a number of things but I can't seem to get it working correctly. 我已经尝试了很多方法,但是似乎无法正常工作。

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. 这里from_dateto_date是您传递的日期。

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' 

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. 您在查询中缺少AND条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM