【问题标题】:Table data formatting ( Data from database)表格数据格式化(来自数据库的数据)
【发布时间】:2019-04-14 05:48:00
【问题描述】:

获取数组数据并使用explode 我已经分离了内容。现在,我想在列表中打印这些数据。但产品正在生产线上。我尝试使用“break tag”和“list tag”所有可能的方式。

这里是代码

 <tbody id="test">
           @foreach ($data['samplingData'] as $key => $samplingData)
              <tr> <td>{{$samplingData->doctor_name}}</td> 
               <td>{{$samplingData->date}}</td> 
                @foreach(explode(',', $samplingData->products) as $product) 
                    <td> {{$product}} </td>    
                @endforeach

               <td>{{$samplingData->quantity}}</td> </tr>

           @endforeach
         </tbody>

数据以这种方式打印

Name    date      products    quantity
a     12-12-12    a  a  a  a    1 1 1 1 

我想这样打印

Name    date      products    quantity
a      12-12-12     a           1
                    a           1
                    a           1

我尝试在 td 中添加 tr 以及在 td 中添加列表。

请帮我格式化数据。

【问题讨论】:

  • 您在{{$product}} 之后尝试过&lt;BR/&gt; 吗? &lt;td&gt; {{$product}} &lt;BR/&gt; &lt;/td&gt;
  • 是的,我试过了。它没有用。因为我用过 td.它是连续打印产品。我尝试在 td 中创建 tr。还是不行。
  • &lt;td&gt;@foreach(explode(',', $samplingData-&gt;products) as $product) {{$product}} &lt;BR/&gt; @endforeach&lt;/td&gt; ?
  • 知道了。非常感谢
  • 它解决了你的问题吗?

标签: php html css laravel laravel-5


【解决方案1】:

基本上你是在为每个$product创建&lt;td&gt;

 <td>@foreach(explode(',', $samplingData->products) as $product) {{$product}} <BR/> @endforeach</td>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-24
    • 2014-07-19
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    • 2013-06-11
    相关资源
    最近更新 更多