简体   繁体   English

将 Array 数据转换为 html 表

[英]Convert Array data to html table

im having some issues with a array data that i got form a json file, but i guess the issue maybe is with the json structure that that i converted in array using json decode and file_get_contents.我从 json 文件中获得的数组数据存在一些问题,但我想问题可能与我使用 json 解码和 file_get_contents 转换为数组的 json 结构有关。

Basicall this is the array strucutre:基本上这是数组结构:

#items: array:4 [▼
    "Monday, 1 de Fev de 2021" => array:5 [▼
      "PM" => array:7 [▼
        1 => "1140-10"
        2 => "8498-25"
        3 => "7076-19"
        4 => "3380-20"
        5 => "8194-24"
        6 => "8288-22"
        7 => "687-22"
      ]
      "PT" => array:7 [▼
        1 => "6406-2"
        2 => "2976-19"
        3 => "6029-8"
        4 => "8130-8"
        5 => "7530-8"
        6 => "1071-18"
        7 => "064-16"
      ]
      "PTV" => array:7 [▶]
      "PTN" => array:7 [▶]
    ]
    "Sat, 31 de Jan de 2021" => array:2 [▼
      "PTM" => array:7 [▶]
      "PT" => array:7 [▶]
    ]

Basically the date is the table caption, and the index with the letters eg: "PTV","PM","PT"...", are the theader th titles.基本上日期是表格标题,带有字母的索引,例如:“PTV”,“PM”,“PT”...”,是标题。

And inside of the "PM" for example there are some results:例如,在“PM”内部有一些结果:

 1 => "1140-10"
 2 => "8498-25"
 3 => "7076-19"
 4 => "3380-20"
 5 => "8194-24"
 6 => "8288-22"
 7 => "687-22"

Where the indexes (1,2,3..) Are the prize, and the values after each index are the results.其中索引 (1,2,3..) 是奖品,每个索引后面的值是结果。

I need to construct my table to be like this image above我需要将我的表格构建成上面这张图片

在此处输入图像描述

This is my code:这是我的代码:

@if(sizeof($results) > 0)
  @foreach($results as $date => $result)
    <div class="col-xl-12">
      <table class="table">
        <caption>
          {{ $date }}
        </caption>
        <thead>
          <tr>
            <th id="hoje" class="tabla-header"></th>
            @foreach($result as $banca => $re)
              <th id="{{ $banca }}" class="tabla-header">{{ $banca }}</th>
            @endforeach
          </tr>
        </thead>
        <tbody>
          {{ sizeof($result) }}
          @for ($i = 0; $i < 7; $i++)
            <tr>
              <td>1</td>
              @for ($n = 0; $n < sizeof($result); $n++)
                <td>{{ $result[] }}/td>
              @endfor
            </tr>
          @endfor
        </tbody>
      </table>
    </div>
  @endforeach
@endif

create a database and insert into table information.创建数据库并插入表信息。 next with console make:controller // make a controller接下来使用控制台 make:controller // 制作 controller

make a method...( select information of database)制作方法...(数据库的select信息)

          $var1 = DB::table("table_name")->get('column_1');// first use DB namespace
          $var2 = DB::table("table_name")->get('column_2');
          $var2 = $var2[
          // and other get columns table
          return view('view_name',['tr1' => $var1,'tr2' => $var2 /* and etc */);
}

and view is under code并且视图在代码下

<!DOCTYPE htl>
<html>
<table class="table"> <!-- table class ; you create a table class in your code -->
<tr>
<th>{{$var1[0][0]->column_name}}</th>
<th>{{$var1[0][1]->column_name}}</th>
<th>{{$...}}</th>
</tr>
<tr>
<th> {{$avr2[0][0]->column_name}} </th>
<th> {{$var2[0][1]->coumn_name}} </th>
<!-- and continue above code -->
</tr>
</table>
</html>

first you select info of db and show them in view首先你 select 数据库的信息并在视图中显示它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM