从 while 循环中获取一些记录到数组,然后将这些记录通过电子邮件发送

Get some records from a while loop to an array, then send these records in an email

我有一个 while 循环:

$users = mysqli_query($con, "SELECT * FROM table");
while($row = mysqli_fetch_array($users)) {          
  if    ($row['column1'] !=  $row['column2']) {
    echo "There is a different between column1 and column2<br />";
  }
}

我想获取所有 column1column2 不同的记录,并将这些值发送到电子邮件中。

电子邮件如下所示:

ID     Column1   Column2
1      111       222
4      222       333

我以为我可以用 array_push 做到这一点,但我没有让它工作。

知道如何完成这项工作吗?

尝试:

$users = mysqli_query($con, "SELECT * FROM table");
$value = '';
while($row = mysqli_fetch_array($users)) {

    if($row['column1'] !=  $row['column2']) {
       $value .= 'and here the value u want';
    }
}

你是这个意思?让我知道:)

因为你想通过电子邮件发送 HTML table,你只需要创建一个 HTML table 并在每次出现错误时添加一些行.然后将其包含到您的电子邮件内容中并发送邮件。

$users = mysqli_query($con, "SELECT * FROM table");

// Table header
$htmlError = '<table><tr><th>ID</th><th>Column 1</th><th>Column 2</th></tr>';

while($row = mysqli_fetch_array($users)) {

    if  ($row['column1'] !=  $row['column2']) {
        // Add new row to table
        $htmlError .= '<tr><td>'.$row['id'].'</td><td>'.$row['column1'].'</td><td>'.$row['column2'].'</td></tr>';
    }
}

// End table
$htmlError .= '</table>';

// Send mail
...