简体   繁体   中英

PHP IF condition on results of SQL Query

I want to send a mail using PHP Mailer, but first I need to validate 3 tables

This is the code I have,

//First I query the 2 tables to validate today's data and 3rd table to see if mail already sent
$verifyJobData = $dbconnection->query("SELECT id FROM [Jobs] WHERE date=CAST(GETDATE() AS DATE)");
$verifyJobData->fetchAll(PDO::FETCH_OBJ);
$verifyWIPData = $dbconnection->query("SELECT id FROM [WIP] WHERE date=CAST(GETDATE() AS DATE)");
$verifyWIPData->fetchAll(PDO::FETCH_OBJ);
$verifyDuplicateMail = $dbconnection->query("SELECT status FROM [Mail_Log] WHERE mailtype = 'DailyStatus' AND datesent = CAST(GETDATE() AS DATE) AND status = 1;");
$mailStatus = $verifyDuplicateMail->fetchAll(PDO::FETCH_OBJ);
$mailStatus=$mailStatus->status;
//On the first IF I want to validate that IF $mailStatus->status is different than 1 pass to the next IF to validate the other data
if ($mailStatus != 1) //Enter next IF
{ 
    if ($verifyJobData->rowCount() && $verifyWIPData->rowCount())//The select had result continue to send code
    {
        echo "Code to send mail already working";
    }
} else {
    echo "Do not send mail and execute Code to insert failure status to DB also working";
}

The first IF is not validating the $mailStatus IF the value is 0, null or different than 1 also passes to the next IF.

This is what I tried, I did a lot of research but I am not finding what I need I might be searching wrong, also if you can share the URL to read the examples

Try this:

switch($mailStatus){
    case 1:
        echo "Do not send mail and execute Code to insert failure status to DB also working";
        break;

    default:        
        if ($verifyJobData->rowCount() && $verifyWIPData->rowCount()) {
            echo "Code to send mail already working";
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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