Problem with Logical Listing with 3 information

0

I am receiving from the database several clients that have contracts and each contract of these has several documents ... how can I list this using vectors in php? I've been away from the codes for 8 years and I'm coming back for 1 week ... sorry for my ignorance ... I can not 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      
  • Cli2     
    • cont1
    •      
      • doc1      
    • cont2
    •      
      • doc2         
      • doc2      

I was traveling in the vectors and I did not get anything ... please ... could anyone put a template resolution here please ?? My logic was pro sack! Thanks!

I'm almost there, but some records do not appear ... follow the code of the part that prints the documents of the regsitro only, ignoring the part of the clients to facilitate the view and already thank you very much 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");
        }

Resolved 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");
          }
    
asked by anonymous 14.06.2018 / 00:47

0 answers