doutong4088 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);

if(!$r){
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

  • 写回答

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:

    $date=date('Y-m-d');
    if($r['reminder']==$date)
    {
        echo 'Mail sent here';
    }
    else
    {
       echo 'date not match';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?