I want to change the status of all records according to the current date automatically

1

I want to change the status of all the records according to the current date automatically, but the following code updates all the data according to the first record

include('php/connection.php');
$hoy = date('Y-m-d');   
$sql = "select * from agenda";  
$edit = mysql_query($sql,$cn);  
$row = mysql_fetch_array($edit);
$fecDB = $row['fecha_fin'];

if($fecDB<$hoy)
{
    $estado = "VENCIDO";
}
elseif ($fecDB>=$hoy) 
{
    $estado = "EN PROCESO"; 
}    

$sql = "update agenda set estado='$estado' where (fecha_fin<'$hoy')     OR  ".
"(fecha_fin>='$hoy')";
    
asked by Mario Morales 25.04.2017 в 19:08
source

1 answer

2

Try this:

include('php/connection.php');
$hoy = date('Y-m-d');   
$sql = "UPDATE agenda SET estado = IF(fecha_fin<'$hoy','VENCIDO','EN PROCESO');";
  

Tested and working.

    
answered by 25.04.2017 в 19:44