我一直盯着这段代码一小时思考什么是错的,我不知道是什么..它应该只是将总和增加到一个特定的行,而是添加了总结到每一行,我不知道为什么。有人可以帮忙吗?
//adding to analytics of the specific job
$sum = 0;
$yearnow = date("Y");
$monthnow = date("n") - 1;
$daynow = date("j");
$sel_user = "select * from tbl_analytics WHERE `Job_ID`='$jid' AND `Year`='$yearnow' AND `Month`='$monthnow' AND `Day`='$daynow'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
$row = mysqli_fetch_assoc($run_user);
if($check_user>0){
$sum = $row['Sum'];
$sum++;
$sel_user = "UPDATE `peso`.`tbl_analytics` SET `Sum` = '$sum' WHERE `tbl_analytics`.`Job_ID` = '$jid' AND `tbl_analytics`.`Year`='$yearnow' AND `tbl_analytics`.`Month`='$monthnow' AND `tbl_analytics`.`Day`='$daynow'";
$run_user = mysqli_query($con, $sel_user);
}
else{
$sel_user = "INSERT INTO `peso`.`tbl_analytics` (`ID`, `Job_ID`, `Year`, `Month`, `Day`, `Sum`) VALUES (NULL, '$jid', '$yearnow', '$monthnow', '$daynow', '1')";
$run_user = mysqli_query($con, $sel_user);
}
//adding analytics to the overall job
$sum = 0;
$sel_user = "select * from tbl_analytics WHERE `Job_ID`='0' AND `Year`='$yearnow' AND `Month`='$monthnow' AND `Day`='$daynow'";
$run_user = mysqli_query($con, $sel_user);
$check_user = mysqli_num_rows($run_user);
$row = mysqli_fetch_assoc($run_user);
if($check_user>0){
echo "<script>alert('The sum is: " . $row['Sum'] . "')</script>";
$sum = $row['Sum'];
$sum++;
echo "<script>alert('The sum is: " . $row['Sum'] . "')</script>";
$sel_user = "UPDATE `peso`.`tbl_analytics` SET `Sum` = '$sum' WHERE `tbl_analytics`.`Job_ID` = '0' AND `tbl_analytics`.`Year`='$yearnow' AND `tbl_analytics`.`Month`='$monthnow' AND `tbl_analytics`.`Day`='$daynow'";
$run_user = mysqli_query($con, $sel_user);
}
else{
$sel_user = "INSERT INTO `peso`.`tbl_analytics` (`ID`, `Job_ID`, `Year`, `Month`, `Day`, `Sum`) VALUES (NULL, '0', '$yearnow', '$monthnow', '$daynow', '1')";
$run_user = mysqli_query($con, $sel_user);
}