Stop database return - Mysql / PHP

2

I have a problem to finalize a project, I need to return the records of a database table, but in some registers, it has a data stored differently, so I need to stop the execution. I could not find the solution so far.

What I need is to show as a result, how many records are with the status column 0 , limiting at most 6 records, if they have other records after 2 registers with 0 status, stop execution.

Example:

Tabela: 11_07_2017_sala1 id | matricula_aluno | entrada | saida | status 1 | 0 | 6.5 | 7 | 0 2 | 0 | 7 | 7.5 | 0 3 | 2 | 7.5 | 8 | 1 4 | 2 | 8 | 8.5 | 1 5 | 2 | 8.5 | 9 | 1 6 | 0 | 9 | 9.5 | 0

When I made Query with the WHERE status = 0 clause, it jumped the records that are with status = 1 , but continued to display the results of the other records.

I added LIMIT 6 , however, the records kept returning all, except for those where status = 1 , limiting to 6 records.

What would be the correct way for this application?

Thank you!

    
asked by anonymous 11.07.2017 / 23:16

1 answer

1

Your query with the clause WHERE status = 0 will only return values 0 for status, so there is no chance of checking the situation próximo registro o status = 1

Break is used to control structures such as while, from while, for and switch.

The function of break is to force the output of a structure. For example, if we have a repetition structure that goes to a certain number, but that should stop sooner if any conditions are satisfied, in this case we use break.

  

In your case when there are two status 0 followed by a status não 0 OR seis zeros seguidos

//selecione sem where sem limit
SELECT * FROM 11_07_2017_sala1
$zeros=0;

..............................
..............................

    //condição para incrementar numero de status igual a 0
    if($status==0){
        $zeros=$zeros+1;

        //ação enquanto as condições não forem atendidas
        // EXEMPLO
        echo "<tr><td>".$id."</td><td>".$matricula_aluno."</td><td>".$entrada."</td><td>".$saida."</td><td>".$status."</td></tr>";

    }

    //aqui as condições para interromper a iteração
    if ((($zeros==2 && $status!=0))||($zeros==6)){
        break;
    }
    
12.07.2017 / 02:31