2017-10-06 3 views
0

Actuellement, j'ai des éléments de facture dans une table mysql qui renvoient au numéro de facture dans une autre table. Je cours un select * de la requête pour joindre les deux (ci-dessous). Ma question est, comment puis-je créer un while à l'intérieur d'un while? En l'état actuel des choses, j'obtiens plusieurs listes du même numéro de facture pour chaque poste de facture qu'il contient ... J'ai juste besoin de les regrouper pour obtenir un enregistrement de facture, avec la facture enfants sous il.PHP MySQL - Regroupement des enfants associés à la jointure interne de l'enregistrement parent

$result = SELECT * FROM tblinvoices INNER JOIN tblinvoiceitems ON tblinvoices.invoice_id = tblinvoiceitems.invoice_id WHERE invoice_date BETWEEN CURDATE() - INTERVAL 14 DAY AND CURDATE() ORDER BY invoice_date DESC, invoice_time DESC; 


<table style="width: 100%;"> 
    <?php 
    while ($row = mysqli_fetch_assoc($result)) { 
     ?> 

* Démarrage en boucle de facturation ici *

<tr> <td width="6" align='center'> <?php echo($row['invoice_id']);?> 
    </td> 
      <td width="6" align='center'> 
       <?php echo($row['invoice_id']);?> 
      </td> 
      <td width="6" align='center'> 
       <?php echo(date("d/m/Y", strtotime($row['invoice_date'])));?> 
      </td> 
      <td width="6" align='center'> 


     <?php echo(date("g:i A", strtotime($row['invoice_time'])));?> 
     </td> 


    </tr> 


    <tr> 
     <td colspan="4"> 
      <table> 

* Démarrage en boucle articles de facture ici *

<tr> 
    <td align='center'> 

       <?php echo($row['invoice_item_id']);?> 
      </td> 
      <td align='center'> 
       <?php echo($row['invoice_item_name']);?> 
      </td> 
      <td align='center'> 
       <?php echo($row['invoice_item_cost']);?> 
      </td> 
      <td align='center'> 
       <?php echo($row['meal_item_taxed']);?> 
      </td> 
     </tr> 

* Fin de facture Articles en boucle *

 </table> 
    </td> 
</tr> 

* Fin facture boucle ici *

<?php 
} 
?> 
<tfoot> 

Je ne suis pas sûr de savoir comment faire la boucle while quand je suis déjà un.

Toute aide serait grandement appréciée. :-)

Répondre

0

J'ai partagé un exemple qui vous aide à résoudre votre problème. Si ce n'est pas le cas, partagez tout votre code afin que je puisse vous aider à le résoudre.

<!DOCTYPE html> 
<html> 
<head> 
    <title>Testing</title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <style type="text/css"> 
    .finder { 
     display: none; 
    } 
    </style> 
</head> 
<body> 
<table> 
    <tr> 
     <td>HELLO</td> 
     <td>HELLO 1</td> 
     <td>HELLO 2</td> 
     <td>HELLO 3</td> 
     <td>HELLO 4</td> 
     <td class="clickme">HELLO 5</td> 
    </tr> 
    <tr class="finder"><td>123456</td></tr> 
    <tr> 
     <td>HELLO</td> 
     <td>HELLO 1</td> 
     <td>HELLO 2</td> 
     <td>HELLO 3</td> 
     <td>HELLO 4</td> 
     <td class="clickme">HELLO 5</td> 
    </tr> 
    <tr class="finder"><td>356454756</td></tr> 
    <tr> 
     <td>HELLO</td> 
     <td>HELLO 1</td> 
     <td>HELLO 2</td> 
     <td>HELLO 3</td> 
     <td>HELLO 4</td> 
     <td class="clickme">HELLO 5</td> 
    </tr> 
    <tr class="finder"><td>96723234</td></tr> 
    <tr> 
     <td>HELLO</td> 
     <td>HELLO 1</td> 
     <td>HELLO 2</td> 
     <td>HELLO 3</td> 
     <td>HELLO 4</td> 
     <td class="clickme">HELLO 5</td> 
    </tr> 
    <tr class="finder"><td>756756</td></tr> 
</table> 
</body> 
<script type="text/javascript"> 
$(document).ready(function() { 
    $('.clickme').click(function() { 
     $(this).parent('tr').next().toggle(); 
    }); 
}); 
</script> 
</html> 

Veuillez demander n'importe quelle requête si vous avez.

Passez une bonne journée.

+0

Salut, désolé ... La réponse que vous avez fournie ne correspond pas à ce que je cherchais. Je cherche une solution PHP, pas une solution jQuery. J'ai mis à jour ma question pour éviter toute confusion :-) – cloudseeker