【问题标题】:Array Explode values in single database table with 3 different rows print in a table how?如何在一个表中打印 3 个不同行的单个数据库表中的数组 Explode 值?
【发布时间】:2019-02-13 09:11:44
【问题描述】:

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

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

源代码是这样的

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

这里分享一下我的数据库截图和前视图

删除空格并继续值

【问题讨论】:

    标签: php mysql mysqli explode mysqlimport


    【解决方案1】:

    您的问题出在您的 for 循环中,$lenght 是类别数,但是您从 0 循环到 $lenght 而不是 0 到 $lenght-1 循环,这会导致空白行。将您的 for 语句更改为:

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

    【讨论】:

    • i 会像
    • @NagendraKumar 将其更改为我在答案中写的内容。请注意,&lt;= 已更改为 &lt;
    • 我会改变你上面写的我会改变
    • 这里我有 5 个值,但是一旦看到我的数据库水泥两次和 BMData,qwert,asdds 只显示 3 个值,但我只打印水泥,qwertd,sdsdsd
    【解决方案2】:
    <?php for($i=0; $i< $lenght; $i++) i will change thar <= replace to < then output will came 
    

    { ?>

    做点什么

    } ?>

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 2016-10-08
      • 2014-04-15
      相关资源
      最近更新 更多