Hello people I have that code
<a href='procesar_eliminar_novedad.php?id=<?php echo $crow['id'];?>'>
<i class="fas fa-trash-alt" style="color: darkred" onClick="return confirmar()"></i>
</a>
that takes me to a script that deletes the news, but that news is related to another table that counts how many news you have created.
I need to delete that novelty and update the other table that keeps the count, so when I delete it will be -1 in the other table.
Someone could help me.
Thank you
That's what process_remove_newness.php does
mysqli_query($conn, "DELETE FROM novedad WHERE id='$id'");
If I do another query:
$conta_area = "UPDATE area SET contador_area = contador_area - 1 WHERE nombre_area='$nombre_area'";
mysqli_query($conn, $conta_area);
it doesn't do anything, it doesn't bring me the variable $name_area
That is the query that I bring all.
$base = "SELECT empleados.id_empleado, empleados.nombre_empleado, empleados.area_id, empleados.f_actual,
novedad.cargo, novedad.fechaactual, novedad.id, novedad.licenciatipo1, area.nombre_area, area.id_area FROM empleados LEFT JOIN novedad ON novedad.id_empleado=empleados.id_empleado INNER JOIN area ON empleados.area_id=area.id_area WHERE MONTH(fechaactual) = MONTH(CURRENT_DATE()) UNION SELECT empleados.id_empleado, empleados.nombre_empleado, empleados.area_id, empleados.f_actual, novedad.cargo, novedad.fechaactual, novedad.id, novedad.licenciatipo1, area.nombre_area, area.id_area FROM empleados LEFT JOIN novedad ON novedad.id_empleado=empleados.id_empleado
INNER JOIN area ON empleados.area_id=area.id_area WHERE MONTH(fechaactual) = MONTH(CURRENT_DATE()) ORDER BY id DESC";
$nquery = mysqli_query($conn, $base);
It is about getting the value of the common field between both tables, which seems to be
nombre_area
.So you should try this out before proceeding with the registry deletion query.
Given your query and what I have understood of how these tables are related, try this other one to see if it works:
And then the following query with the UPDATE should work fine for you, because you will already have assigned that variable that you were missing. (That is if I have understood you correctly... if not then tell us what it is that goes wrong now)