Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

252
Vistas
Expiry date IF santance is not working with MYSQL UPDATE

I have table with many rows. I have exp date and I want to change status of those rows where date is already exp.

It work well if I do not use UPDATE. If I just echo them. But when I want to UPDATE status of this row to 0, problems start. My problem is that it change only 1 row and not all of them that needs to be whit status 0.

$sql = "SELECT * FROM table";
$result = mysqli_query($conn, $sql);
$resultcheck = mysqli_num_rows($result);
$id = $row['id'];

if($resultcheck > 0) {
while($row = mysqli_fetch_assoc($result)) {

$expdate = $row['date'];
$exp = strtotime($date);

$today = date('m/d/Y');
$td = strtotime($today);

if($td>$exp) {
$status=0;

$sql = " UPDATE table SET status = '$status' WHERE ID = '$id' ";
$result = mysqli_query($conn, $sql);
}
}
}

Any advice how to fix that, I tried several option but nothing worked.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

  1. Use row['id'] instead of $id.

$sql = " UPDATE table SET status = '$status' WHERE ID = 'row['id']' ";

  1. Rename $result for update. You are reusing the same variable name, hence, after a success update, it will set $result to true and the while loop will stop.
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda