session_start();
// USER PROCESS DATE
$process_update = $baglan->prepare('SELECT * FROM user_process where process_user = ? and process_type = 1');
$process_update->execute(array($user['user_koloni']));
$process = $process_update->fetch(PDO::FETCH_ASSOC);
$koloni_data = $baglan->prepare('SELECT * FROM koloni_data WHERE koloni_id = ?');
$koloni_data->execute(array($user['user_koloni']));
$koloni = $koloni_data->fetch(PDO::FETCH_ASSOC);
if ($process_update->rowCount())
{
$date=date_create($process['process_date']);
$now=date_create(date("Y-m-d H:i:s"));
$difference=date_diff($date,$now);
$month = $difference->format("%m")*43200;
$day = $difference->format("%d")*1440;
$hour = $difference->format("%h")*60;
$minute = $difference->format("%i");
$result = $month+$day+$hour+$minute;
$user_minute_product = $koloni['koloni_production'] / 60;
$count_milk = $user_minute_product * $result;
if ($result == 0) { } else {
$user_product_update = $baglan->prepare('UPDATE koloni_data SET koloni_milk = koloni_milk + ? where koloni_id = ?');
$user_product_update->execute(array($count_milk,$user['user_koloni']));
$process_delete = $baglan->prepare('DELETE FROM user_process WHERE process_user = ? and process_type = 1');
$process_delete->execute(array($koloni['koloni_id']));
}
}
else
{
$process_insert = $baglan->prepare('INSERT INTO user_process (process_user,process_date,process_type) values (?,?,1)');
$process_insert->execute(array($user['user_koloni'],date("Y-m-d H:i:s")));
}
$koloni_data = $baglan->prepare('SELECT * FROM koloni_data where koloni_id = ?');
$koloni_data->execute(array($user['user_koloni']));
$koloni = $koloni_data->fetch(PDO::FETCH_ASSOC);
?>
Kodlar bu şekilde ama mesela diyelim saatte 10.000 üretim yapması lazım ama 8bin bazen 7 bin bazen hiç yapmıyor duruyor nerde hata var acaba ?