我正在尝试查看此方案的最佳方法 - 我想在用户更新特定列时发送电子邮件警报。列名是rep。如果rep列未更新,请不要发送电子邮件。
这是我的尝试:
<?php
$dom = new DomDocument("1.0", "utf-8");
$dom->loadXML(file_get_contents("export.txt"));
$xpath = new DomXPath($dom);
$entries = $xpath->query("/locations/devices/entry");
$count = 0;
// $entries is a DomNodeList
var_dump($entries);
foreach ($entries as $entry) {
//do stuff with $entry
}
所以看起来像这样吗?
<?php
$dom = new DomDocument("1.0", "utf-8");
$dom->loadXML(file_get_contents("export.txt"));
$devices = $dom->getElementsByTagName('devices');
$entries = [];
foreach ($devices as $device) {
foreach ($device->childNodes as $child) {
if ($child instanceof DomElement && $child->tagName === "entry") {
$entries[] = $child;
}
}
}
// $entries is an array of DomElement
var_dump($entries);
foreach ($entries as $entry) {
//do stuff with $entry
}
&GT;
答案 0 :(得分:2)
选择当前值,并将其与插入的值进行比较,如果它不同则需要更新?
$query = mysqli_query($mysqli, "SELECT rep FROM employee WHERE id='$id'");
$row = $query->fetch_assoc()[0];
if($row['rep'] != $_POST['rep'])
$record_update = true;
答案 1 :(得分:0)
这可能不是最佳答案,但我建议您捕获第一次插入的日期和时间,然后更新将它们记录在表列中,并比较更新发生时的时间或两者数据行。
$query = mysqli_query($mysqli, "SELECT time, date FROM employee WHERE id='$id'");
$row = $query->fetch_assoc()[0];
if($row['time'] > $_POST['time'] || $row['date'] > $_POST['date'])
$record_update = true;