数组在单个数据库表中的爆炸值与3个不同的行打印在一个表中如何?

问题描述 投票:0回答:2

大家好,我有爆炸功能的问题。

在我的数据库中,我有一个没有行的表,有些行数据保存为逗号分隔,一些行保存为逗号分隔。

我的问题是爆炸值一些空值也查看如何停止该值。

源代码看起来像这样

<table id="datatable" class="table table-bordered">
                 <thead>
                    <tr>
                       <th>Sl.No</th>
                       <th>Item Name </th>
                       <th>Category</th>
                       <th>Brand</th>
                       <th>Qty</th>
                       <th>Unit Price</th>
                       <th>Amount</th>
                       <th>Pic</th>
                       <th>Others</th>
                    </tr>
                 </thead>
                 <tbody>
                    <?php
                    require_once("../dbconfig.php");
                    extract($_REQUEST);

                    $sql="SELECT * FROM `purchase_data` where project_id='$proid'";
                    $result = $conn->query($sql);
                    $count=$result->num_rows;
                    if ($count > 0) {
                    $x=1;
                    while ($pur_row = $result->fetch_assoc()) {
                           $proid =$pur_row['pur_id']; 

                            $category = $pur_row['pur_category'];
                            $categories = explode(',',$category);
                            $lenght = count($categories);

                            print_r($categories);

                            $product = $pur_row['pur_itemname'];
                            $products = explode(',',$product);

                            $brand = $pur_row['pur_brand'];
                            $brands = explode(',',$brand);

                            $unitprice = $pur_row['pur_rate'];
                            $unitprices = explode(',',$unitprice);

                            $qty = $pur_row['pur_qty'];
                            $quantity = explode(',',$qty);

                            $remarks = $pur_row['pur_others'];
                            $remark = explode(',',$remarks);

                            $est_amou = $pur_row['pur_amount'];
                            $est_amount = explode(',',$est_amou);

                            $edr_others = $pur_row['pur_others'];
                            $edr_other = explode(',',$edr_others);
                             ?>
                             <?php for($i=0; $i<=$lenght; $i++)
                                {  ?>
                    <tr>
                       <td><?=$x;?></td>
                       <td><?=$products[$i];?></td>
                       <td><?=$categories[$i];?></td>
                       <td><?=$brands[$i];?></td>
                       <td><?=$quantity[$i];?></td>
                       <td><?=$unitprices[$i];?></td>
                       <td><?=$est_amount[$i];?></td>
                       <td></td>
                       <td><?=$edr_other[$i];?></td>
                    </tr>
                   <?php $x++;  }  } }  ?>
                 </tbody>
             </table>

在这里,我将分享我的数据库和前视图的屏幕截图

database look like this

front end look lie this

删除空格并继续值

mysql mysqli explode mysqlimport
2个回答
1
投票

你的问题在你的for循环中,$lenght是类别的数量,但是你从0循环到$lenght而不是0到$lenght-1,这导致空行。将您的for声明更改为:

<?php for($i=0; $i < $lenght; $i++)

1
投票
<?php for($i=0; $i< $lenght; $i++) i will change thar <= replace to < then output will came 

{ ?>

做一点事

} ?>

© www.soinside.com 2019 - 2024. All rights reserved.