0

我正在使用 passthru 文件更新由 ajax 函数触发的数据库。阿贾克斯是:

    $("#updateInventory").live('click', function() {
    $('#updateInventory').attr('disabled', 'disabled');

    $.ajax({
            type: "POST",
            url: "updateInventoryExecmws.php",//
            dataType: "json",
            success: function(data){
                                update = data.update;
                                console.log(data);
                                if (update == true){
                alert(data.message);
                                } else {
                                $('#message').html(data.saying);
                                   }
                            }

    });
});

并且通过文件是:

    <?php
passthru('php /home/bookcell/public_html/testbcos/mbas/updateInventorymws.php >> /home/bookcell/public_html/testbcos/exports/mbas.txt &');

$saying = array('saying' => 'Updating Inventory for today. An email will be sent as soon as the update is finished.');

echo json_encode($saying);
?>

这一切正常,并启动 updateInventorymws.php 文件。在这里,我需要检查更新今天是否已经完成,是否已经提醒用户并停止执行脚本。除了警报,这一切都正常工作。这是此的代码:

    //inventory already been updated today?
$updatedTodayResult = $conn->query("SELECT * from order_sold where date_sold between NOW() - interval 5 minute and NOW()");

$updatedTodayRows = $updatedTodayResult->num_rows;
if($updatedTodayRows < 1){
    $updatedToday = false;
    $note = "Updating Inventory for today. An email will be sent as soon as the update is finished.";
}else{
    $updatedToday = true;
    $note = "Inventory is already updating for today.";

}
    if($updatedToday == false){
    // run the update here
    }
    $records = $x;

$to = "myemail@me.com";
$subject = "Update Inventory Report";
$body = $records . " records were successfully updated in today's inventory update!";
mail($to, $subject, $body);
$message = array('message' => $note,
      'update' => $updatedToday,
      );

}else{
$records1 = 'Someone has attempted to run Update Inventory more than once today. If this problem shouldn\'t occur, please see administrator.';

$to = "myemail@me.com";
$subject = "Update Inventory Report";
$body = $records1;
mail($to, $subject, $body);
$message = array('message' => $note,
      'update' => $updatedToday,
      );    
}

echo json_encode($message);

有没有办法让它从中创建警报,以便用户知道更新已经完成?

4

0 回答 0