Page 1 sur 1

Stocké dans une variable

Posté : 08 août 2015, 16:21
par fabrice88250
bonjour,
est-il possible de stocké des echo et un foreach dans une seule variable.
En fait je voudrai le resultat du tableau qui s'affiche dans une variable pour pouvoir ensuite l'envoyer par mail.

Code : Tout sélectionner

echo '<table class="tg" width="100%"> <tr> <th class="tg-031e">Ref</th> <th class="tg-031e">P.U.</th> <th class="tg-031e">Quatit&eacute</th> <th class="tg-031e">Total</th> </tr>'; foreach ($resultats as $arrayElement){ echo '<tr>'; echo '<td class="tg-031e">'.$arrayElement['nom'].'</td>'; echo '<td class="tg-031e">'.$arrayElement['prix'].' &#128;</td>'; echo '<td class="tg-031e">'.$arrayElement['quantite'].'</td>'; echo '<td class="tg-031e">'.$arrayElement['quantite'] * $arrayElement['prix'].'</td>'; echo '</tr>'; } echo '</table> '; ?>

Re: Stocké dans une variable

Posté : 08 août 2015, 16:27
par nestecha
function display_tg_tds($aDatas) {
foreach ($aDatas as $arrayElement){
   echo '<tr>';
   echo '<td class="tg-031e">'.$arrayElement['nom'].'</td>';
   echo '<td class="tg-031e">'.$arrayElement['prix'].' &#128;</td>';
   echo '<td class="tg-031e">'.$arrayElement['quantite'].'</td>';
   echo '<td class="tg-031e">'.$arrayElement['quantite'] * $arrayElement['prix'].'</td>';
   echo '</tr>';
   }
}
Dans un autre fichier functions.php que tu inclues.

Et ensuite :
echo '<table class="tg" width="100%">
        <tr>
         <th class="tg-031e">Ref</th>
         <th class="tg-031e">P.U.</th>
         <th class="tg-031e">Quatit&eacute</th>
         <th class="tg-031e">Total</th>
        </tr>';
display_tg_tds($resultats);
echo '</table> ';