0

I tried Laravel Controller Inside Function Make Html Table All are Worked But table body inside i want multiple row so tried this code not worked properly code

 $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>';

I want this type of code inside the body of 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>';

2 Answers 2

2

You can do it like this.

<?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;
Sign up to request clarification or add additional context in comments.

Comments

1
 $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>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.