0

我在遍历行、更新字段、然后根据日期发送电子邮件时遇到问题。我也可以让第一行发送电子邮件,但我不知道为什么我不能让其他行发送电子邮件。我可以显示返回了三行但我无法发送三封电子邮件。代码如下,提前感谢您的帮助。

<?php




    for($numOfRows = 1; $numOfRows > 0;){       

    $sql = "SELECT * FROM service WHERE boosterDate BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY";

if(!$result = $con->query($sql)){
    die('There was an error running the query [' . $con->error . ']');  
    }

    $numOfRows = $result->num_rows;
    //%result->store_result();
    $numOfRows = var_dump($numOfRows);
    //echo $numOfRows;

//if($numOfRows > 0){

    //var_dump($numOfRows);

while($row = $result->fetch_array()){
        //Get all the rows and store them in an array   
    $firstQueryRows[] = $row;

}

foreach($firstQueryRows as $row){

    //do a new query with $row
    $serviceID = $row['serviceID'];
    $patientID = $row['patientID'];
    $serviceName = $row['serviceName'];
    $price = $row['price'];
    $quantity = $row['quantity'];
    $boosterDate = $row['boosterDate'];
    $totalPrice = $row['totalPrice'];
    $rabiesTagNumber = $row['rabiesTagNumber'];
    $microChipNumber = $row['microChipNumber'];
    $rabiesDose = $row['rabiesDose'];
    $rabiesVacType = $row['rabiesVacType'];

    $rabiesVacExpDate = $row['rabiesVacExpDate'];
    $rabiesSerialNumber = $row['rabiesSerialNumber'];
    $rabiesManufacturer = $row['rabiesManufacturer'];
    $rabiesVacDate = $row['rabiesVacDate'];
    $rabiesVacDueBy = $row['rabiesVacDueBy'];
    $licenseNumber = $row['licenseNumber'];
    $isThisARabiesCert = $row['isThisARabiesCert'];
    $vacDate = $row['vacDate'];
    $email30 = $row['email30'];
    $email60 = $row['email60'];
    $email90 = $row['email90'];     
    //echo $serviceID . "  ";
    $sql = "UPDATE service SET email30 = 30 WHERE serviceID = $serviceID";

    if(!$result = $con->query($sql)){
    die('There was an error running the query [' . $con->error . ']');  
    }

    }//End Foreach



    //echo $patientID;


    $sql = "SELECT * FROM service WHERE email30 = 30";
    if(!$result = $con->query($sql)){
    die('There was an error running the query [' . $con->error . ']');  
    }

    while($row = $result->fetch_array()){
        //Get all the rows and store them in an array   
    $firstQueryRows[] = $row;

    $patientID = $row['patientID'];
    //echo $patientID;

}

    foreach($firstQueryRows as $row){



        $sql = "SELECT * FROM patientInformation WHERE patientID = $patientID";
    if(!$result = $con->query($sql)){
    die('There was an error running the query [' . $con->error . ']');  
    }       

    }

    while($row = $result->fetch_array()){
        $firstQueryRows[] = $row;
        $clientID = $row['clientID'];
        $maleFemale = $row['maleFemale'];
        $species = $row['species'];
        $ageYears = $row['ageYears'];
        $ageMonths = $row['ageMonths'];
        $weight = $row['weight'];
        $dogBreed = $row['dogBreed'];
        $name = $row['name'];
        $catBreed = $row['catBreed'];
        $colors = $row['colors'];
        $illnessLast30Days = $row['illnessLast30Days'];
        $explainIllness = $row['explainIllness'];


        //echo $clientID;   

    }

    foreach($firstQueryRows as $row){

        $sql = "SELECT * FROM clientInformation WHERE clientID = $clientID";
    if(!$result = $con->query($sql)){
    die('There was an error running the query [' . $con->error . ']');  
    }

    }

    while($row = $result->fetch_array()){

        $firstName = $row['firstName'];
        $lastName = $row['lastName'];
        $address = $row['address'];
        $city = $row['city'];
        $zip = $row['zip'];
        $phone = $row['phone'];
        $cell = $row['cell'];
        $state = $row['state'];
        $email = $row['email'];




    }

    $to = $email;
    $subject = "Just a friendly reminder from the Shot Spot";


    $message = "Greetings " . $firstName . " " .    $lastName . "\r\n" . "\r\n" . "\r\n"  .
        "Thank you for choosing the Shot Spot for all of your animals healthcare needs.  This is a friendly reminder that  
                            " . $name . " is ready for their booster on " . $boosterDate . "\r\n" . "\r\n" . "\r\n" . 
                            "Thank you for choosing the Shot Spot";


    $headers = 'From: info@txshotspot.com';

    mail($to, $subject, $message, $headers);



}//end for loop


?>
4

1 回答 1

0

您没有通过 for 循环进行迭代,并且您的代码有点混乱:p。你想发送三封电子邮件试试这个:

for($numOfRows = 0; $numOfRows <= 3; $numOfRows++)
于 2013-11-13T02:42:47.057 回答