AJAX - auto update mysql

 
Vista:
sin imagen de perfil

auto update mysql

Publicado por vp (1 intervención) el 07/12/2015 18:28:45
quiero realizar un update automatico, por ejemplo quiero sacar la diferencia de dias entre la fecha actual y una fecha predeterminada, teniendo la diferencia de dias quiero compararla con un valor fijo (TIEMPO) DE LA TABLA BONOS, si este entra entre los parametros quiero que actualize el campo CATEGORIA DE LA TABLA HISTORIALBONOS. alguna propuesta?

TABLA BONOS
ID | CATEGORIA | TIEMPO
1 | PREMIO_1 | 30
2 | PREMIO_2 | 60
3 | PREMIO_3 | 90
4 | PREMIO_4 | 120
5 | PREMIO_5 | 150
6 | PREMIO_6 | 180

TABLA HISTORIALBONOS
IDHISTORIAL | IDEMPLEADO | CATEGORIA | FECHA INICAL
1 | 2 | PREMIO_1 | 30/11/2015


//RESTA DIAS FECHA ACTUAL - FECHA INICIAL
$hoy = date('d-m-Y');
$fechainicial = $row_historialbonos['fechainicial'];

function dateDiff($start, $end) {
$start_ts = strtotime($start);
$end_ts = strtotime($end);
$diff = $end_ts - $start_ts;
return round($diff / 86400);
} //fin de comparacion

echo dateDiff("$fechainicial", "$hoy");

<?php
//actualizar categoria automaticamente al comparar diferencia de dias con tiempo
$valorinput = $_POST['diasinc'];
$valoridhistorial = $_GET['idhistorial'];


if ($valorinput < 30){

}
else if (($valorinput > 31) && ($valorinput < 59)){

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'UPDATE historialbonos SET categoria="PREMIO_2"
WHERE idhistorial = $valoridhistorial';

mysql_select_db('basededatos');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);

}
else if (($valorinput > 60) && ($valorinput < 89)){
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'UPDATE historialbonos SET categoria="PREMIO_3"
WHERE idhistorial = '.$valoridhistorial;

mysql_select_db('basededatos');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else if (($valorinput > 90) && ($valorinput < 119)){

}
else if (($valorinput > 120) && ($valorinput < 149)){

}
else if (($valorinput > 150) && ($valorinput < 179)){

}
else if ($valorinput >= 180){

}
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder