Problem with PHP conditions

2

This is my problem, I'm doing a form to record resolutions, it turns out that one of the conditions must be that there can not be two active resolutions at the same time, so I did this:

$ques = "SELECT COUNT(*) as total FROM resolucion WHERE estado = '1'"; 
$eje=mysql_query($consul);
$reso = mysql_fetch_assoc($eje);
   .El estado es 1, ya que 1 es activo y 0 inactivo

if($reso['total']<1){
  me ejecuta la actualización
}elseif($reso['total']>=1){
  no ejecuta la actualización
}

The problem is that as I am saying that if the active resolutions are greater than or equal to 1, I do not allow the execution of the update, but taking into account that I want to update a resolution that is active, it would not let me because it is having in account that resolution, that is, there is already an active resolution and that is what I want to edit but it does not leave me, but with this validation I can avoid registering two or more active resolutions, but not allowing me to edit the one that is already active.

    
asked by lina salazar 01.12.2018 в 04:38
source

2 answers

0

try this to see:

if ($ reso ['total'] = 1) {   I executed the update } elseif ($ reso ['total'] > = 1) {   does not run the update }

It must be equal "=" to one, because "less than" 1 would be 0 or less.

    
answered by 01.12.2018 в 13:03
0

The condition would be as follows:

if(int() $reso['total'] == 1){
    echo "Ejecuto la actualización";
} else {
    echo "No ejecuto la actualización";
}

The cast conversion may be over, but it could be useful if the values return them as a string and may prevent a correct comparison.

    
answered by 01.12.2018 в 13:21