while循环未执行后的语句

时间:2015-09-22 16:54:47

标签: php mysql database connection

我正在尝试在向用户发送电子邮件之前从邮件列表中删除用户。但是,第二个while循环中负责此操作的代码未执行。

有人能看出这是为什么吗?

<?php
$query = "SELECT * FROM remove_request";
$result = mysqli_query($dbc,$query);
if($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
        $query = "DELETE FROM mail_table WHERE first_name='" . $row["first_name"]
            . "' AND last_name='"     . $row["last_name"]
            . "' AND email_address='" . $row["email_address"] . "'";
        $result = mysqli_query($dbc,$query);
        echo $row["first_name"] . ' has been removed from the mail list.';
    }
}

$query = "SELECT * FROM mail_table";
$result = mysqli_query($dbc,$query) or die('Error querying database');
if($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
        mail($row["email_address"],$subject,$message,$headers);
        echo 'email sent to ' . $row["first_name"] . "\n";
    }
}
mysqli_close($dbc);
?>

0 个答案:

没有答案