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

Asked

Viewed 327 times

0

I’m having a hard time retrieving information.

In the data for printing, I need to show in the variable $comp when she belongs to the same id_cadastro that I am consulting, so far everything well, worked out, but I have several $comp for the same id_cadastro, to $comp is equal to consultation d_comp bank, and in some cases I have up to 10 $comp, I’m trying to show you when to ($comp for =1 show the d_comp 1) concerning the id_cadastro of the query, when the variable $volume is equal to $comp = 1 show its value. Then I get the $comp 2 and successively.

I’ve tried to if, not of the expected value, I’m here with the while but it won’t go.

Follow the code below:

<?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 table register is where the customer and other data is, and the id of this table is in the table decontamination which in turn will have up to 10 register for the same registration id, and in printing this report I need to define to which data $d_comp when equal to 1, show the data of the d_comp = 1 the decontamination table, the id x of the registration table and when the $d_comp is equal to 2 show data from d_comp of the same id x of the registration table.

  • @Andreicoelho will be able to help me in this too?

1 answer

0

From what I understand, you want to search the data with the same id as 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'];

    }
}

That’s right?

  • almost that, but I’ve tried it and it didn’t work, I’ll try to put here the code for you to understand.

  • @Juniorvenancio blz, I’ll wait

  • edited my question @Wotonsampaio with the code, what do you think?

  • Dude, when I create a table that has for example users, and another that has their data, I make in the second table a field with the name idcli that receives the account id, every time the user throws the data there, that idcli gets its id from the main table, so in the search I do q neither in the example I did above, I think it gets more practical

  • In the search, I just need to search all with the idcli corresponding to the user id, understand? The way you did you’re comparing all the fields

  • then but I’m doing so, as said the table decontamination carries the id of the register, but in the case then I gather more tables on account of other information that must be printed together, understand, because this decontamination can be done in several compartments, and in printing if there is more than one decontaminated compartment, it has to be printed as well, but each compartment has its own information.

Show 1 more comment

Browser other questions tagged

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