Join repeated results - PHP

Asked

Viewed 383 times

1

Good morning to everyone, I have a question to join repeated results in the query in Mysql made by PHP.

It is the following the code that I am using at the moment it removed the first repetition of values in the query, but there is another field that should also be removed the duplicates, I have tried several combinations that I understand and nothing worked, it is returning this way:

Cliente Tipo Análise
   1      1    0001
          1    0002
---------------------
   2      1    0100

And I’m willing to do so:

Cliente Tipo Análise
   1      1    0001
               0002
---------------------
   2      1    0100

Note that in the Type field, you are repeating the values.

I have N clients, and this client has N reviews, I can not repeat the client in the survey and neither the type, why will put together everything in the Analysis part, forming a list.

The code I’m currently using:

$query = mysqli_query( $db, 'SELECT * FROM laudos ORDER BY cliente, tipo');
$cli = array();

while($row = $query->fetch_assoc()) {
    $cli[$row['cliente']][] = $row;
}
?>

<table border="1" cellpadding="10">
<tr>
    <td>Cliente</td>
    <td>Tipo</td>
    <td>Análises</td>
</tr>
<?php 
    foreach($cli as $cliente => $values){
?>
<tr>
    <td><?php echo $cliente; ?></td>
    <?php foreach($values as $resul) { ?>
    <tr>            
        <td></td>
        <td>
            <?php echo $resul['tipo'];?>
        </td>
        <td>
            <select>
                <option SELECTED>Escolha um laudo</option>
                <option><?php echo $resul['legisla'].'-'.$resul['numero'];}?></option>
            </select>
        </td>
    </tr>
</tr>
    <?php } ?>

1 answer

0

good try to be clearer, can not comment.

want to use combobox with values is?

why do so $cli[$Row['client']][] = $Row;?

the correct form is $Rows['table name'] = $Row; or $Rows[] = $Row; to take all fields bd

  • then you have to go to the type column and see if the previous Dice already exists something like if(type[i]==type[i++]){echo }Else{}

Browser other questions tagged

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