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:
you need to compare the zero section with all? or you need to compare the current section with the next one?
– rray
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.
– Sr. André Baill
That’s when I really thought, just wonder if
$idDadosAnt
always must be zero.– rray
But it is still incorrect... It should not always be zero, it has to go through. according to the excerpts
– Sr. André Baill
cannot increment it in if or Else?
– rray
http://i.stack.Imgur.com/Og2ti.png takes a look at the result
– Sr. André Baill