0
I am receiving from the database several clients who have contracts and each contract of these has several documents... how can I list this using vectors in php? 8 years since I was away from the codes and I’m going back to 1 week... sorry my ignorance... I’m not able to solve this logic...
ex:
cli1 - cont1 - doc1
cli1 - cont1 - doc2
cli2 - cont1 - doc1
cli2 - cont2 - doc1
cli2 - cont2 - doc2
print as follows:
- Cli1
- cont1
- doc1
- doc2
- cont1
- doc1
- cont2
- doc2
- doc2
I was traveling in the vectors and did not get anything... please... could someone put a resolution model here please?? my logic went to bag! Thank you!
I’m almost there... However, there are no records... follow the code of the part that prints the regsitro documents only, ignoring the part of customers to facilitate the view and I thank you very much for the help _/_:
If($auxCont=="")//primeiro contrato
{
$contrato = "ID do Contrato: ".$dados->Campo("IDContrato");
$html.=ImLinCSS(array($contrato), $arr_largCol, $arr_alinCol, $lin, "ContSubOn1");
$auxCont=$dados->Campo("IDContrato");
}
if($auxCont == $dados->Campo("IDContrato")) //se for o mesmo contrato do registro
{
//imprime os documentos do contrato
$doc = $dados->Campo("Descricao");
$html.=ImLinCSS(array($doc), $arr_largCol, $arr_alinCol, $lin, "ContSubOf1");
}
else
{//se for um segundo contrato
$contrato = "ID do Contrato: ".$dados->Campo("IDContrato");
$html.=ImLinCSS(array($contrato), $arr_largCol, $arr_alinCol, $lin, "ContSubOn1");
$auxCont=$dados->Campo("IDContrato");
//imprime o primeiro documento do segundo contrato e adiante
$doc = $dados->Campo("Descricao");
$html.=ImLinCSS(array($doc), $arr_largCol, $arr_alinCol, $lin, "ContSubOf1");
}
Solved and Optimized:
$auxCli = ""; //cliente começa sendo nenhum
$auxCont = ""; //contrato começa sendo nenhum
while ($dados->LeProxReg())
{
if ($auxCli != $dados->Campo("CodCliente")) //Trocou o Cliente
{
$cliente = "Código do Cliente: " . $dados->Campo("CodCliente") . " - " . $dados->Campo("Nome");
if ($dados->Campo("EhPessJuridic") == "S")
$cliente .= " - CNPJ" . $dados->Campo("CNPJ");
else
$cliente .= " - CPF" . $dados->Campo("CPF");
$html .= ImLinCSS(array($cliente), $arr_largCol, $arr_alinCol, $lin, "ContOn1");
If ($auxCont != $dados->Campo("IDContrato")) //trocou contrato
$html .= ImLinCSS(array("ID do Contrato: " . $dados->Campo("IDContrato")), $arr_largCol, $arr_alinCol, $lin, "ContSubOn1");
}
$auxCont = $dados->Campo("IDContrato");
$auxCli = $dados->Campo("CodCliente");
$html .= ImLinCSS(array($dados->Campo("Descricao")), $arr_largCol, $arr_alinCol, $lin, "ContSubOf1");
}
Search by multidimensional array. Like Iterate, it’s with
foreach
.– MagicHat
The logic, very briefly, is to control whether you have printed every value that can be repeated. For example, when passing the second row of data in your example, you don’t print
cli1
norcont1
, onlydoc2
. You also need to control what level of the tree you are on.– bfavaretto
They always come ordered, or the order may be different (sautéed)?
– Isac
I got you guys... THANK YOU!!! Put the resolution?
– Reculos Gerbi Neto
Yes, please. Posting the solution is always good because it can help other people with similar problems.
– bfavaretto