php, bring multiple rows from a linked table to another table of a single id

0

Hello,

I'm having a hard time retrieving information.

EDITING TO IMPROVE THE QUESTION

Below is the code,

In the data for printing, I need to show in the variable $ comp when it belongs to the same id_cadastro I am querying, so far so good, it worked, but I have vario $ comp for the same id_cadastro, $ comp equals d_comp query from the bank, and in some cases I have up to 10 $ comp, and I'm trying to show, where comp $ comp = 1 show d_comp 1 for query id_cadastro, qndo to $ volume equals $ comp = 1 show your worth. Then I have the $ comp 2 ............

This is the situation, I need a lot of help from you, already tried if, does not give the expected value, I'm here with the while but tbm will not.

data for printing

<?php   require_once("logica_usuario.php");
        verificaUsuario();
        require_once('forms_funcoes.php');

$id = $_GET['id'];
$imp = impLaudos($conexao, $id);

?>
<body onLoad="javascript:window.print();">
<table width="1411" height="1889" border="0" bordercolorlight="#FC0004" >
  <tbody>


    <tr>
      <td height="29">&nbsp;</td>
      <td colspan="5"><?=$imp['cadEquip']?></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="6"><?=$imp['cadInmetro']?></td>
      <td colspan="9"><?=$imp['cadCapaci']?></td>
      <td colspan="6"><?=$imp['cadMarca']?></td>
    </tr>

    <tr>
      <td height="30">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>

      //daqui para baixo

      <td colspan="2">
          <?php
            //$comp = compartimento
            $comp = $imp['d_comp'];
            $i = 1;
          while($i == $comp){
              echo $comp;
            $i++;
          }

          ?></td>
      <td colspan="2">
        <?php

            if($comp == 2){
                echo $comp;

            } else {

                echo "";
            }

        ?>

        </td>
      <td>

          <?php

            if($comp == 3){
                echo $comp;

            } else {

                echo "";
            }

        ?>

        </td>
      <td colspan="3">

          <?php

            if($comp == 4){
                echo $comp;

            } else {

                echo "";
            }

        ?>

        </td>
      <td colspan="2">

        <?php

            if($comp == 5){
                echo $comp;

            } else {

                echo "";
            }

        ?>

        </td>

    </tr>

here is the function impLaudo

function impLaudos($conexao, $id){
    $query = "select desco.*, 
        cli.cli_nome as nomeCli,
        cli.cli_cnpj as cnpjCli,
        cad.condutor as cadCondutor,
        cad.condutor_cpf as cadCondutor_cpf,
        cad.placa as cadPlaca,
        cad.id_cli,
        cad.data as cadData,
        cad.id as cadId,
        cad.marca_modelo as cadMarcaModelo,
        cad.chassi as cadChassi,
        cad.equipamento as cadEquip,
        cad.num_imetro as cadInmetro,
        cad.capacidade as cadCapaci,
        cad.marca as cadMarca,
        cad.id_fin as cadFinalidade,
        cad.id_proc as cadProcesso
        from descontaminacao as desco
        left join cadastro as cad on cad.id = desco.id_cadastro
        left join cliente as cli on cli.id = cad.id_cli


    where desco.id = {$id}";
    $resultado = mysqli_query($conexao, $query);
    return mysqli_fetch_assoc($resultado);

}

The 'register' table is where the customer data and other data is stored, and the id of this table is in the 'decontamination' table, which in turn will have up to 10 records for the same registration id, and in the printing of this report I I need to set the $ d_comp data to equal 1, show the d_comp = 1 data from the decontamination table, the id x from the register tab, and when $ d_comp is equal to 2 it shows the d_comp data of the same id x of the registration tab.

    
asked by anonymous 15.02.2018 / 03:09

1 answer

0

So I understand, you want to fetch the data with the same id from the other table, is that right? If it is you can use:

<?php
$mysqli = new mysqli("host", "user", "password", "db");

if ($sth = $mysqli->query("SELECT * FROM suatabela WHERE id='idquevocêbusca'")){
    while ($row = $sth->fetch_assoc()) {
           echo $row['id'];

    }
}

Is that right?

    
15.02.2018 / 03:24