2017-06-22 12:48
浏览 108

使用日期比较从mysql DB检索数据

I want to send a reminder to my subscribers a month before their subscription ends, i have columns validity and reminder (type VARCHAR) in my MYSQL DB

date stored in those columns are saved using php date function

$validity = date('d/m/Y',strtotime("6 months"));
$reminder = date('d/m/Y',strtotime("5 months"));

now i want to send a mail when the current date is equals reminder date I have a test entry with reminder value 22/06/2017 and $date variable echo the same value.

$date = date('d/m/Y');

$q = 'SELECT * FROM subscriptions WHERE reminder = "$date"';
$r = mysql_query($q);

echo 'query err';

$a = mysql_num_rows($r);
echo 'No of rows returned '.$a;

*mailing script after this line*

this script outputs No of rows returned 0

Can someone give me some idea how i should approach this

图片转代码服务由CSDN问答提供 功能建议

我想在订阅结束前一个月向我的订阅者发送提醒,我列有效期和 我的MYSQL DB中的提醒(类型VARCHAR)

存储在这些列中的日期使用php date function

  $保存 validity = date('d / m / Y',strtotime(“6个月”)); 
 $提醒=日期('d / m / Y',strtotime(“5个月”)); 

现在我想在当前日期等于提醒日期时发送邮件 我有一个带有提醒值的测试条目22/06/2017和$ date变量回显相同的值。

  $ date = date('d / m / Y'); 
 $ q ='SELECT * FROM subscriptions WHERE reminder =“$ date”'; \  n $ r = mysql_query($ q); 
if(!$ r){
echo'query err'; 
 $ a = mysql_num_rows($ r); 
echo'返回行数 '。$ a; 



  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

6条回答 默认 最新

  • dphphvs496524 2017-06-22 12:57

    First i suggest you your date format is change in database and type change datetime.

    This format follow for you insert reminder date

    $reminderdate = date('Y-m-d');

    Then compare with currentdate when fetch data from database:

        echo 'Mail sent here';
       echo 'date not match';
    解决 无用
    打赏 举报