现在,程序在一定程度上运行良好,当 mysql_affected_rows 大于 0 时,它确实将数据添加到新表并打印出相关的回显消息。
但是,当 mysql_affected_rows = 0 时,我什么也没得到,没有错误消息,但完全没有输出。
我已经剥离了代码,你们有任何想法吗,我查看了括号和关闭条件等,但无法找出原因!
代码
$query10 = ("SELECT p.surname, p.passNo, p.activeUntil FROM PASSENGER p WHERE p.activeUntil < DATE_ADD(NOW(),INTERVAL -1 DAY)");
$result = mysql_query($query10);
while($row = mysql_fetch_array($result))
{
$surname = $row['surname'];
$passNo = $row['passNo'];
mysql_query("INSERT INTO ARCHIVED_PASSENGER (surname, passNo) VALUES ('$surname', '$passNo') ")
or die(mysql_error());
if (mysql_affected_rows()>0) {
echo '<p>';
echo "The number of rows affected by this update is: ";
echo mysql_affected_rows();
}
if (mysql_affected_rows()<1) {
echo '<p>';
echo "No records were affected. Taking you back to the control panel.";
}
}