Check that all elements are equal

2

I'm retrieving all the expired tickets from the database, with the following query

SELECT user,status,hash 
      FROM ticket 
      WHERE datepay < date_add(now(), interval -1 month) AND user = '119'

The result is as expected, as below. It reads status:usuário

  

0: 118 0: 119 0: 119

But I need to check if all statuses are 1 (means paid), if there is at least one user with 0: 119 already invalid. I have tried to use array_unique, however it will check all users and I will not know which did not pay all.

    
asked by anonymous 17.05.2018 / 19:55

1 answer

1

What you need is to deal with for , logic is simple

Se user.status == 0 então diga "usuário pendente"; 
  parar;
senão
  "o usuário está em dias";

In practice it would look something like this, considering that the%% variable is the query object ( $ftc ):

for($i = 0; $i <= count($ftc); $i++){
  if($ftc[$i]["status"] == "0"){
    echo "O usuário {$ftc[$i]["user"]} ainda tem fatura pendente".PHP_EOL;
    break;
  }else{
    echo "O usuário {$ftc[$i]["user"]} pode ser liberado".PHP_EOL;
  }
}

Since you said that if at least one ticket is pending is no longer valid, then you do not need to check all the elements, just stop the iteration of X user and continue to the next, recursively.

Cons

If there are many users pending, the application will be slow, leading to a high cost in server performance.

    
17.05.2018 / 21:43