Comparison of Cities between Stretches

Asked

Viewed 101 times

2

Hello! I am developing a system that consists of registering sections by neighborhood or city. In this case, which I am taking as an example, it includes only two excerpts, as I show in the figure. My question is, how to buy the stretches that are coming from the array(), I know that in the first stretch the cities are the same, but how to buy the second stretch, and there may be more stretches?

The code I developed is as follows::

$intContagem = 1;
$intContagemArray = count($dados)-1;

for($idDados = 1; $idDados<=$intContagemArray; $idDados++){
    $idDadosAnt = 0;

    if($dados[0]['cidade'] == $dados[1]['cidade']){
        $sql = "SELECT $strSelect as vlrFrete FROM tabelafrete WHERE idSaida = ".$dados[$idDadosAnt]['bairro']." AND idDestino = ".$dados[$idDados]['bairro']."";   
    } else {
        $sql = "SELECT $strSelect as vlrFrete FROM tabelafretem WHERE idSaida = ".$dados[$idDadosAnt]['cidade']." AND idDestino = ".$dados[$idDados]['cidade']." AND referencia = 'C'";
    }

    $consulta = $this->db->query($sql)->result();
        foreach($consulta as $valor){
            $intContagem += $valor->vlrFrete;
        }
}

Comparative excerpt:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

  • you need to compare the zero section with all? or you need to compare the current section with the next one?

  • The comparison should be made between sections. Section 1, I check if the city is equal to Section 2, Section 2, I check if the city is equal to Section 3, and so on... But I got the solution using the variables we already had available. I posted the solution, see if it would be ideal, please.

  • That’s when I really thought, just wonder if $idDadosAnt always must be zero.

  • But it is still incorrect... It should not always be zero, it has to go through. according to the excerpts

  • cannot increment it in if or Else?

  • http://i.stack.Imgur.com/Og2ti.png takes a look at the result

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.