douhan4812 2017-12-19 10:17
浏览 173

如何从数据库中获取数据并以表格格式显示?

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

                            }
                        }
                    }
                }
            }
        }
    }
}
  • 写回答

1条回答 默认 最新

  • dongqiao9394 2017-12-19 10:39
    关注
    <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/

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog