简体   繁体   English

Cron Job-为什么我的php脚本不仅选择一天(我希望它能正常工作),所以现在还选择了7天

[英]Cron Job - why does my php script select not only one day (as I want it to work) which is 7 days forwads from right now but it selects

ID  | Client  |    Data    | Hosting   | Price |
    |         |            |           |       |
    |         | 2017-11-23 | Heineken  | 500   |
    |         | 2017-11-22 | Hestia    | 200   |
    |         | 2017-11-21 | Bravo     | 200   |
    |         | 0000-00-00 |           |       |
    |         | 0000-00-00 |           |       |

Why when I want the PHP code to select only the record with date 23-11-2017 which is 7 days from right now (16-11-2017) my scirpt somehow selects EACH SINGLE DAY from now (16-11-2017) up to 23-22-2017, namely 2017-11-22 and 2017-11-21...(above is my MySql table from which I select mentioned records) 为什么当我希望PHP代码仅选择日期为23-11-2017(即现在(16-11-2017)为7天)的记录时,我的脚本以某种方式选择了现在(16-11-2017)的每个单日到23-22-2017,即2017-11-22和2017-11-21 ...(以上是我的MySql表,我从中选择提到的记录)

This is my cronejob.php code: 这是我的cronejob.php代码:

<?php

    use PHPMailer\PHPMailer\PHPMailer;
    include_once "PHPMailer/PHPMailer.php";
    include_once "PHPMailer/Exception.php";

    $mysqli = new mysqli('localhost', 'stdeja_genek', 'haslo', 'stdeja_genek');

    $tbl_2 = $mysqli->query( "SELECT * FROM klienci WHERE date(Data) BETWEEN CURTIME() AND DATE_ADD(CURTIME(), INTERVAL 7 DAY);");

    if($tbl_2->num_rows == 1) {
        $mail = new PHPMailer();
        foreach($tbl_2 as $email => $details) {        
            $fullname = $details['Klient'] . ' ' . $details['Data'];

            $mail->addAddress('piterdeja@gmail.com');
            $mail->setFrom('system_przypomnien_hosting@powiadomienia.pl');
            $mail->Subject = "Hosting - system przypomnień";
            $mail->isHTML(true);
            $mail->Body = "W dniu {$details['Data']} kończy się hosting klientowi {$details['Klient']} na KWOTĘ {$details['Cena']}, hosting to {$details['Hosting']}";

            if ($mail->send())
                echo "Formularz został wysłany. Postaramy się odpowiedzieć jak najszybciej.";
            else
                echo 'Mailer Error: ' . $mail->ErrorInfo;
        }             
    }  
?>

Wait... you want it to select one day 7 days from now, but you're using BETWEEN . 等一下...您希望它从现在起7天选择一天,但是您正在使用BETWEEN Why not just use = ? 为什么不只使用=

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

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