Массив Разнесите значения в одной таблице базы данных с 3 различными строками, напечатанными в таблице. Как? - PullRequest
0 голосов
/ 13 февраля 2019

Привет всем, у меня проблема с функцией разнесения.

В моей базе данных у меня есть одна таблица без строк, есть ли некоторые строки данных, сохраненные как разделенные запятыми, а некоторые строки сохраняются без разделенных запятыми.

Моя проблема в том, чтобы разобрать значения, некоторые пустые значения также показывают, как остановить эти значения.

исходный код выглядит так

<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

удаление пробелов и продолжение значений

Ответы [ 2 ]

0 голосов
/ 13 февраля 2019
<?php for($i=0; $i< $lenght; $i++) i will change thar <= replace to < then output will came 

{?>

сделать что-то

}?>

0 голосов
/ 13 февраля 2019

Ваша проблема в цикле for, $lenght - это количество категорий, но вы циклически изменяете от 0 до $lenght вместо 0 до $lenght-1, что приводит к пустым строкам.Измените ваше заявление for на:

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