-1

I am using following code to fetch data from database . its show my output correct when i insert all columns value . for example i insert NULL values for 'Hip' so its not showing in tabular format .

Please help me for the same Thanks in advance!

$sizeArray         = explode(',', $rows['sizes']);
$bustArray         = explode(',', $rows['bust']);
$hipArray          = explode(',', $rows['hip']);
$lengthArray       = explode(',', $rows['length']);
$lengthArraybottom = explode(',', $rows['lengthbottom']);
$shoulderArray     = explode(',', $rows['shoulder']);

foreach ($sizeArray as $key => $value) {
    foreach ($bustArray as $bkey => $bvalue) {
        foreach ($waistArray as $Wkey => $Wvalue) {
            foreach ($hipArray as $hkey => $hvalue) {
                foreach ($lengthArray as $lkey => $lvalue) {
                    foreach ($lengthArraybottom as $lkeybottom => $lbottomvalue) {
                        foreach ($shoulderArray as $skey => $svalue) {
                            if ($key == $bkey && $bkey == $Wkey && $Wkey == $hkey && $hkey == $lkey && $lkey == $lkeybottom && $lkeybottom == $skey) {

                                echo '<tr><td>' . $value . '</td>';
                                echo '<td>' . $bvalue . '</td>';
                                echo '<td>' . Wvalue . '</td>';
                                echo '<td>' . $hvalue . '</td>';
                                echo '<td>' . $lvalue . '</td>';
                                echo '<td>' . $lbottomvalue . '</td>';
                                echo '<td>' . $svalue . '</td></tr>';

                            }
                        }
                    }
                }
            }
        }
    }
}
Tobias F.
  • 1,050
  • 1
  • 11
  • 23
shail
  • 97
  • 9
  • https://stackoverflow.com/questions/14827380/how-can-i-fetch-data-from-database-in-php-using-mysql – TarangP Dec 19 '17 at 10:20
  • 1
    I'm finding it difficult to understand your data structure and your question in general. Could you post your input? I feel like 7 foreach loops is a bit overkill for what you wish to achieve – IsThisJavascript Dec 19 '17 at 10:20
  • please take a look at https://stackoverflow.com/questions/13961388/display-php-array-result-in-an-html-table – Gaurav Singh Faujdar Dec 19 '17 at 10:21

1 Answers1

0
<table class="data-table">
    <caption class="title">Sales Data of Electronic Division</caption>
    <thead>
        <tr>
            <th>NO</th>
            <th>CUSTOMER</th>
            <th>ITEM</th>
            <th>DATE</th>
            <th>AMOUNT</th>
        </tr>
    </thead>
    <tbody>
    <?php
    $no     = 1;
    $total  = 0;
    while ($row = mysqli_fetch_array($query))
    {
        $amount  = $row['amount'] == 0 ? '' : number_format($row['amount']);
        echo '<tr>
                <td>'.$no.'</td>
                <td>'.$row['name'].'</td>
                <td>'.$row['item'].'</td>
                <td>'. date('F d, Y', strtotime($row['date'])) . '</td>
                <td>'.$amount.'</td>
            </tr>';
        $total += $row['amount'];
        $no++;
    }?>
    </tbody>
    <tfoot>
        <tr>
            <th colspan="4">TOTAL</th>
            <th><?=number_format($total)?></th>
        </tr>
    </tfoot>
</table>

Refrence : http://webdevzoom.com/display-mysql-data-html-5-table-using-php/