Я попытался Laravel Controller внутри функции Сделать HTML-таблицу Все работают, но тело таблицы внутри я хочу несколько строк, поэтому попробовал этот код не работал должным образом код

 $contents = '<table class="border" style="margin-top: 2%">
                           <thead>
                                <tr>
                                    <th>SNo</th>
                                    <th>Specification</th>
                                    <th>Description</th>
                                    <th>Qty</th>
                                    <th>UOM</th>
                                    <th>Unit Price</th>
                                    <th>Disc</th>
                                    <th>Net Price</th>
                                </tr>
                           </thead>
                           <tbody>
                              '.foreach ().'
                            </tbody>
                        </table>';

Я хочу этот тип кода внутри тела таблицы

echo '<tr>
                        <td>'.$k.'</td>
                        <td>'.$v->Specification.'</td>
                        <td>'.$v->Description.'</td>
                        <td>'.$v->Quantity.'</td>
                        <td>'.$v->UOM.'</td>
                        <td>'.$v->Unit_Price.'</td>
                        <td>'.$v->Discount.'</td>
                        <td>'.$v->Net_Price.'</td>
                   </tr>';
php
0
Aravinth E 19 Авг 2019 в 09:30

2 ответа

Лучший ответ

Вы можете сделать это вот так.

<?php

$contents = '<table class="border" style="margin-top: 2%">
                           <thead>
                                <tr>
                                    <th>SNo</th>
                                    <th>Specification</th>
                                    <th>Description</th>
                                    <th>Qty</th>
                                    <th>UOM</th>
                                    <th>Unit Price</th>
                                    <th>Disc</th>
                                    <th>Net Price</th>
                                </tr>
                           </thead>
                           <tbody>';

foreach( $array as $value ){ // your array here                          
   $contents .=  "<tr>";

   $contents .=  "<td>".$k."</td>";
   $contents .=  "<td>".$v->Specification."</td>";
   $contents .=  "<td>".$v->Description."</td>";
   $contents .=  "<td>".$v->Quantity."</td>";
   $contents .=  "<td>".$v->UOM."</td>";
   $contents .=  "<td>".$v->Unit_Price."</td>";
   $contents .=  "<td>".$v->Discount."</td>";
   $contents .=  "<td>".$v->Net_Price."</td>";

   $contents .= "</tr>";

};

$contents .= '</tbody></table>';              

echo $contents;
2
little_coder 19 Авг 2019 в 06:47
 $contents = '<table class="border" style="margin-top: 2%">
                           <thead>
                                <tr>
                                    <th>SNo</th>
                                    <th>Specification</th>
                                    <th>Description</th>
                                    <th>Qty</th>
                                    <th>UOM</th>
                                    <th>Unit Price</th>
                                    <th>Disc</th>
                                    <th>Net Price</th>
                                </tr>
                           </thead>
                           <tbody>';
foreach () {
    $contents .= '<tr><td>'.$k.'</td></tr>'; // other tds here too
}
$contents .= '</tbody></table>';
1
u_mulder 19 Авг 2019 в 06:35