Group information with a common variable in PHP + SQL SERVER

Asked

Viewed 52 times

1

I am developing a code where I have some related tax notes for a user ( unique id ) and when you take the information comes me several lines with the user name and the corresponding tax note , however I would like it to be grouped .

How are you today :

inserir a descrição da imagem aqui

How I wanted you to stay :

inserir a descrição da imagem aqui

Follows my code :

<?php 
session_start();
            $serverName = "DB_NAME";
            $connectionInfo = array( "Database"=>"TABELA_NAME", "UID"=>"USUARIO", "PWD"=>"SENHA" );
            $conn = sqlsrv_connect($serverName, $connectionInfo);
                 if ($conn === false) {
                  die(print_r(sqlsrv_errors(), true));
}

 $query = ("SELECT * FROM PEDIDOS");
 $params = array(); 
 $options = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
 $stmt = sqlsrv_query($conn, $query, $params, $options);

?>
    <?php include("cabecalho.php")?>

        <br>
        <!-- ##### Breadcrumb Area Start ##### -->

        <center>
            <a href="index.php" class="nav-brand"><img src="img/logo.png" alt=""></a>
        </center>
        <br>
        <center>
            <table class="table">
                <thead class="thead-dark">
                    <tr>

                        <th>
                            <center>PEDIDOS</center>
                        </th>
                        <th><a onClick="window.print()" /><i class="fas fa-print"></a></th>
                </tr>
            </thead>

        </table>
    </center>

                <?php while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {  ?>

    <center>
        <table class="table">
            <thead class="thead-dark">
               <tr>

                    <th>
                        <center>ID_Usuarios</center>
                    </th>
                    <th>
                        <center>Nota Fiscal</center>
                    </th>
<th>
                        <center>Data</center>
                    </th>
<th>
                        <center>Frete</center>
                    </th>
                </tr>
            </thead>
            <tbody>
                           <td>
                            <center>
                                <?php echo $row['ID']; ?>
                            </center>
                        </td>
   <td>
                    <?php echo $row['NF']; ?>
                   </td>

                        <td>
                            <center>
                               <?php echo date('d/m/y');?>
                            </center>
                        </td>

                   <td>
                    <?php echo $row['FRETE']; ?>
                   </td>

         </tbody>
         </table>
         </center>

         <br><br><br>
                <?php } 
    ?>

    <!-- ##### Breadcrumb Area End ##### -->
    <?php include("rodape.php")?>
  • I don’t quite understand the problem.. Do you want when the id doesn’t repeat itself? Don’t find it more business to control that in the code?

No answers

Browser other questions tagged

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