Focus an entire array on a variable that prints in DOMPDF

Asked

Viewed 85 times

0

I read a few posts here, but nothing that would give me a north. I have a php that I printed in PDF, with two querys that consult the database, one table has a foreing key of the other. That is, for a key I have several lines in another table. I made two Querys because the table SOFTWARE, also has a line with the name of NAME and I can not change this name.

$query = mysqli_query($cx, "SELECT h.NAME, h.IPSRC, h.PATRIMONIO, h.PRIVILEGIO, n.MACADDR, r.NOME_RESPONSAVEL, r.MAT FROM hardware as h, softwares as s, networks as n, responsavel as r WHERE h.ID = s.HARDWARE_ID AND h.IPSRC = '{$ip}' AND h.ID = n.HARDWARE_ID AND r.ID = h.ID_RESP LIMIT 1");
            while($aux = mysqli_fetch_assoc($query)) {
            $mat = $aux["MAT"];
            $nome_resp = $aux["NOME_RESPONSAVEL"];
            $host =  $aux["NAME"];
            $numpat =  $aux["PATRIMONIO"];
            $privilegio = $aux["PRIVILEGIO"];
            $mac = $aux["MACADDR"];
            }

$sql = mysqli_query($cx, "SELECT s.NAME FROM hardware as h, softwares as s WHERE h.ID = s.HARDWARE_ID AND h.IPSRC = '{$ip}' ORDER BY s.NAME");
            while($aux = mysqli_fetch_assoc($sql)) { 

                $soft = $aux["NAME"];
            }

        //referenciar o DomPDF com namespace
        use Dompdf\Dompdf;

        // include autoloader
        require_once("dompdf/autoload.inc.php");

        //Criando a Instancia
        $dompdf = new DOMPDF();

        // Carrega seu HTML
        $dompdf->load_html('

        <BR><BR><center><b>TERMO DE COMPROMISSO PRESTAÇÃO DE SERVIÇO</b></center><BR><BR>

            <div id="lista" style="text-align: justify;">Pelo presente documento, eu, Matrícula: '.$mat.', '.$nome_resp.', perante a EMPRESA, na qualidade de  Prestador de serviço, responsabilizo-me pelo uso da Estação de trabalho '.$numpat.' com as seguintes configurações:</justify><BR><BR>
            <b>II – Programas:</b><BR>
            a) Programas instalados: '.$soft.' <BR>


        ');

In the variable $soft, I have a list of programs allowed by the company to be used, but DOMPDF only lists the last programs in the list, so I thought of an array.

Give me a boost, guys!

1 answer

1


You don’t have to use array, one string can do it. When you search the value for $soft every iteration you are overriding the value obtained in the previous iteration.

I modified the line where you take the value to $soft, instead of overwriting I used the operated .= to concatenate the existing value into $soft with the value obtained in the iteration.

$query = mysqli_query($cx, "SELECT h.NAME, h.IPSRC, h.PATRIMONIO, h.PRIVILEGIO, n.MACADDR, r.NOME_RESPONSAVEL, r.MAT FROM hardware as h, softwares as s, networks as n, responsavel as r WHERE h.ID = s.HARDWARE_ID AND h.IPSRC = '{$ip}' AND h.ID = n.HARDWARE_ID AND r.ID = h.ID_RESP LIMIT 1");
            while($aux = mysqli_fetch_assoc($query)) {
            $mat = $aux["MAT"];
            $nome_resp = $aux["NOME_RESPONSAVEL"];
            $host =  $aux["NAME"];
            $numpat =  $aux["PATRIMONIO"];
            $privilegio = $aux["PRIVILEGIO"];
            $mac = $aux["MACADDR"];
            }

$sql = mysqli_query($cx, "SELECT s.NAME FROM hardware as h, softwares as s WHERE h.ID = s.HARDWARE_ID AND h.IPSRC = '{$ip}' ORDER BY s.NAME");
            while($aux = mysqli_fetch_assoc($sql)) { 

                // A cada iteração você concatena o valor anterior com o atual
                $soft .= ($aux["NAME"] . '<BR>');
            }

        //referenciar o DomPDF com namespace
        use Dompdf\Dompdf;

        // include autoloader
        require_once("dompdf/autoload.inc.php");

        //Criando a Instancia
        $dompdf = new DOMPDF();

        // Carrega seu HTML
        $dompdf->load_html('

        <BR><BR><center><b>TERMO DE COMPROMISSO PRESTAÇÃO DE SERVIÇO</b></center><BR><BR>

            <div id="lista" style="text-align: justify;">Pelo presente documento, eu, Matrícula: '.$mat.', '.$nome_resp.', perante a EMPRESA, na qualidade de  Prestador de serviço, responsabilizo-me pelo uso da Estação de trabalho '.$numpat.' com as seguintes configurações:</justify><BR><BR>
            <b>II – Programas:</b><BR>
            a) Programas instalados: '.$soft.' <BR>


        ');

Browser other questions tagged

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