我有幾個陣列,包含的值是這樣的:
我有幾個陣列,包含的值是這樣的:
Array
(
[0] => Array
(
[NAMA_MDS] => AGUNG RUDIYANTO
[呼叫] => 182
[RO] => 151
[NAMA_SGRUP] => Kanzler單打
[EC] =>247
[OT] =>57
[Ratio] => 4
[SBQ] => 6586[/span
)
[1] => Array
(
[NAMA_MDS] => AGUNG RUDIYANTO
[呼叫] => 182
[RO] => 151
[NAMA_SGRUP] => Yogurt Squeeze 120 GR
[EC] => 271OT] =>103
[Ratio] =>2
[SBQ] => 9449[/span
)
[2] => Array
(
[NAMA_MDS] => AGUNG RUDIYANTO
[呼叫] => 182
[RO] => 151
[NAMA_SGRUP] => 酸奶飲料 250 ML
[EC] => 271 毫升
[OT] =>106
[Ratio] => 2
[SBQ] => 4960[/span
)
正因為如此,當我把資料傳到我的表中時,結果是這樣的:
。table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
< div class="table-responsive">
<table class="table-striped"/span> style="width: 100%;">
<thead>
<tr>/span>
<th rowspan="2"/span>> Nama銷售</th>>
<th rowspan="2" width="20%"> Nama Barang</th>。
<th colspan="2"/span>> EC</th>
<th colspan="2"/span>> OT</th>/span>
<th rowspan="2"/span>> Ratio</th>
<th rowspan="2"/span>> 銷售量</th>/span>
<th colspan="2"/span>> Drop Size</th>
</tr>/span>
<tr>/span>
<-- <th width="100%">Nama Barang</th> -->
<th>total</th>< th width="10%">% vs Call</th>
<th>total</th>></totalth> th width="10%">% vs Call</th>
<! -- <th>比率</th>
<th>銷售QTY</th> -->
<th>/span>Per-EC</th> <th>Per-OT</th>
</tr>/span>
</thead>/span>
<tbody>/span>
<tr>/span>
<td>AGUNG RUDIYANTO</td>
<td><small> Kanzler單打</small></td>>
<td>/span>247</td>/span>
<td>/span>100%</td>/span>
<td>/span>57</td>/span>
<td>/span>38%</td>/span>
<td>/span>4</td>/span>
<td>/span>6,586</td>/span>
<td>/span>27</td>/span>
<td>/span>116</td>/span>
</tr>/span>
<tr>/span>
<td>AGUNG RUDIYANTO</td>
<td><small> Yogurt Squeeze 120 GR</small> </td>
<td>/span>271</td>/span>
<td>/span>100%</td>/span>
<td>/span>103</td>/span>
<td>/span>69%</td>/span>
<td>/span>2</td>/span>
<td>/span>9,449</td>/span>
<td>/span>35</td>/span>
<td>/span>92</td>/span>
</tr>/span>
<tr>/span>
<td>AGUNG RUDIYANTO</td>
<td><small> Yoghurt Drink 250 ML</small></td>>
<td>/span>271</td>/span>
<td>/span>100%</td>/span>
<td>106</td>/span>
<td>/span>71%</td>/span>
<td>/span>2</td>/span>
<td>/span>4,960</td>/span>
<td>/span>19</td>/span>
<td>/span>47</td>/span>
</tr>/span>
</tbody>/span>
</table>/span>
</div>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
而我想實作的是有這樣的表格:
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
< div class="table-responsive"/span> style="overflow: scroll;height: 500px;">
<table class="table-striped"/span> style="width: 100%;">
<thead>
<tr>/span>
<th rowspan="2"/span>> Nama銷售</th>>
<th rowspan="2" width="20%"> Nama Barang</th>。
<th colspan="2"/span>> EC</th>
<th colspan="2"/span>> OT</th>/span>
<th rowspan="2"/span>> Ratio</th>
<th rowspan="2"/span>> 銷售量</th>/span>
<th colspan="2"/span>> Drop Size</th>
</tr>/span>
<tr>/span>
<-- <th width="100%">Nama Barang</th> -->
<th>total</th>< th width="10%">% vs Call</th>
<th>total</th>></totalth> th width="10%">% vs Call</th>
<! -- <th>比率</th>
<th>銷售QTY</th> -->
<th>/span>Per-EC</th> <th>Per-OT</th>
</tr>/span>
</thead>/span>
<tbody>/span>
<tr>/span>
<td rowspan="3"/span>> AGUNG RUDIYANTO</td>。
<td><small> Kanzler單打</small></td>>
<td>/span>247</td>/span>
<td>/span>100%</td>/span>
<td>/span>57</td>/span>
<td>/span>38%</td>/span>
<td>/span>4</td>/span>
<td>/span>6,586</td>/span>
<td>/span>27</td>/span>
<td>/span>116</td>/span>
</tr>/span>
<tr>/span>
<td><small> Yogurt Squeeze 120 GR</small> </td>
<td>/span>271</td>/span>
<td>/span>100%</td>/span>
<td>/span>103</td>/span>
<td>/span>69%</td>/span>
<td>/span>2</td>/span>
<td>/span>9,449</td>/span>
<td>/span>35</td>/span>
<td>/span>92</td>/span>
</tr>/span>
<tr>/span>
<td><small> Yoghurt Drink 250 ML</small></td>>
<td>/span>271</td>/span>
<td>/span>100%</td>/span>
<td>/span>106</td>/span>
<td>/span>71%</td>/span>
<td>/span>2</td>/span>
<td>/span>4,960</td>/span>
<td>/span>19</td>/span>
<td>/span>47</td>/span>
</tr>/span>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
我想,如果我錯了,請糾正我,我必須使陣列看起來像這樣才能實作我想要的表格:
Array
(
[NAMA_MDS] => AGUNG RUDIYANTO =>
[0] => Array
(
[Call] => 182] => 陣列(
[RO] => 151247 [OT] => 247
[OT] => 574 [SBQ] => 4
[SBQ] => 6586[/span
)
[1] => Array
(
[Call] => 182] [RO] => 182
[RO] => 151120 GR
[EC] => 271103 [OT] => 103
[比率] => 2 [SBQ] => 2
[SBQ] => 9449[/span
)
[2] => Array
(
[Call] => 182] [RO] => 182
[RO] => 151250 ML
[EC] =>271 271 ML
[OT] => 106 [OT
[比率] => 2 [SBQ] => 2
[SBQ] => 4960[/span
)
或類似的東西,但我不知道如何實作我想要的表格。 誰能告訴我如何在改變陣列形狀或不改變陣列形狀的情況下實作我想要的那個表格?
這里是我的控制器:
public function test(){
$data['db_default'] = $this-> db_default-> default();
$data['report2'] = $this-> m_report-> table2($data['db_default'][0]['databasename'])。)
$data['content'] = 'tempelates/KL/Report_B'。
$this->load->view('Tempelate',$data) 。
這是我的視圖中的代碼:
<tbody>/span>
<? php foreach($report2-> result_array() as $row){
$Call = $row['Call'/span>]。
$vsc = ceil(($row['EC']*100)/$Call) 。
$RO = $row['RO'/span>]。
$vsr = ceil(($row['RO']) string">'OT']*100)/$RO)? >?
<tr>
<td>< ? =$row['NAMA_MDS']? ></td>
<td><small><? =$row['NAMA_SGRUP']? ></small> </td>
<td><? =$row['EC']? ></td>
<td>< ? php if($vsc >=100){echo '100%'; }else{echo $vsc. '%';}?></td>
<td>< ? =$row['OT']? ></td>
<td>< ? php if($vsr >= 100){echo '100%'; }else{echo $vsr. '%';}?></td>
<td>< ? =$row['Ratio']? ></td>>
<td>< ? =number_format($row['SBQ'])? ></td>
<td>< ? =ceil($row['SBQ']/$row['EC'])? ></td>
<td>< ? =ceil($row['SBQ']/$row['OT'])? ></td>>
</tr>/span>
<?php }? >
</tbody>
uj5u.com熱心網友回復:
<?php
$report =
array(
array(
( 'NAMA_MDS' =>' AGUNG RUDIYANTO' ,
'Call' =>182,
'RO' => 151,
'NAMA_SGRUP' => 'kkk' ,
'EC' => 247,
'OT' => 57,
'Ratio' => 4,
'SBQ' => 6586,
),
array'NAMA_MDS' =>' AGUNG RUDIYANTO' ,
'Call' =>182,
'RO' => 151,
'NAMA_SGRUP' => 'kkk' ,
'EC' => 247,
'OT' => 57,
'Ratio' => 4,
'SBQ' => 6586,
),
);
$html = '; //here
? >
<div class="table-responsive">
<table class="table-striped"/span> style="width: 100%;">
<thead>
<tr>/span>
<th rowspan="2"/span>> Nama銷售</th>>
<th rowspan="2" width="20%"> Nama Barang</th>。
<th colspan="2"/span>> EC</th>
<th colspan="2"/span>> OT</th>/span>
<th rowspan="2"/span>> Ratio</th>
<th rowspan="2"/span>> 銷售量</th>/span>
<th colspan="2"/span>> Drop Size</th>
</tr>/span>
<tr>/span>
<-- <th width="100%">Nama Barang</th> -->
<th>total</th>< th width="10%">% vs Call</th>
<th>total</th>></totalth> th width="10%">% vs Call</th>
<! -- <th>比率</th>
<th>銷售QTY</th> -->
<th>/span>Per-EC</th> <th>Per-OT</th>
</tr>/span>
</thead>/span>
<tbody>
<?php foreach($report as $row){
$Call = $row['Call']。
$vsc = ceil(($row['EC']*100)/$Call) 。
$RO = $row['RO'/span>]。
$vsr = ceil(($row['OT']*100)/$RO) 。
? >
<tr>
<?php if($html ! = $row['NAMA_MDS']){? >//and here
<td rowspan="3">< ? =$row['NAMA_MDS']? ></td>
<?php }
$html = $row['NAMA_MDS'];?>
<td><small><? =$row['NAMA_SGRUP']? ></small> </td>
<td><? =$row['EC']? ></td>
<td>< ? php if($vsc >=100){echo '100%'; }else{echo $vsc. '%';}?></td>
<td>< ? =$row['OT']? ></td>
<td>< ? php if($vsr >= 100){echo '100%'; }else{echo $vsr. '%';}?></td>
<td>< ? =$row['Ratio']? ></td>>
<td>< ? =number_format($row['SBQ'])? ></td>
<td>< ? =ceil($row['SBQ']/$row['EC'])? ></td>
<td>< ? =ceil($row['SBQ']/$row['OT'])? ></td>>
</tr>/span>
<?php }? >
</tbody>
如果你想使行跨度計數動態化,使用你列出的最后一個陣列的索引計數和相同的方法
。uj5u.com熱心網友回復:
。<!DOCTYPE html>
<html>
<body>
<?php
$report =array(
'AGUNG RUDIYANTO'=> array(
array( 'NAMA_MDS' => 'AGUNG RUDIYANTO' ,
'Call' => 182,
'RO' => 151,
'NAMA_SGRUP' => 'kkkk' ,
'EC' => 247,
'OT' => 57,
'比率' => 4,
'SBQ' => 6586,
),
陣列
( 'NAMA_MDS' => ' AGUNG RUDIYANTO' ,
'Call' => 182,
'RO' => 151,
'NAMA_SGRUP' => 'kkkk' ,
'EC' => 247,
'OT' => 57,
'比率' => 4,
'SBQ' => 6586,
),
陣列
( 'NAMA_MDS' => ' AGUNG RUDIYANTO' ,
'Call' => 182,
'RO' => 151,
'NAMA_SGRUP' => 'kkkk' ,
'EC' => 247,
'OT' => 57,
'比率' => 4,
'SBQ' => 6586。
),),
'AGUNG ssRUDIYANTO'=>陣列(
array( 'NAMA_MDS' => 'AGUNG RUDIYANTO' ,
'Call' => 182,
'RO' => 151,
'NAMA_SGRUP' => 'kkkk' ,
'EC' => 247,
'OT' => 57,
'比率' => 4,
'SBQ' => 6586,
),
陣列
( 'NAMA_MDS' => ' AGUNG RUDIYANTO' ,
'Call' => 182,
'RO' => 151,
'NAMA_SGRUP' => 'kkkk' ,
'EC' => 247,
'OT' => 57,
'比率' => 4,
'SBQ' => 6586,
),
陣列
( 'NAMA_MDS' => ' AGUNG RUDIYANTO' ,
'Call' => 182,
'RO' => 151,
'NAMA_SGRUP' => 'kkkk' ,
'EC' => 247,
'OT' => 57,
'比率' => 4,
'SBQ' => 6586。
),),
);
?">。
<div class="table-responsive">
<table class="table-striped"/span> style="width: 100%;">
<thead>
<tr>/span>
<th rowspan="2"/span>> Nama銷售</th>>
<th rowspan="2" width="20%"> Nama Barang</th>。
<th colspan="2"/span>> EC</th>
<th colspan="2"/span>> OT</th>/span>
<th rowspan="2"/span>> Ratio</th>
<th rowspan="2"/span>> 銷售量</th>/span>
<th colspan="2"/span>> Drop Size</th>
</tr>/span>
<tr>/span>
<-- <th width="100%">Nama Barang</th> -->
<th>total</th>< th width="10%">% vs Call</th>
<th>total</th>></totalth> th width="10%">% vs Call</th>
<! -- <th>比率</th>
<th>銷售QTY</th> -->
<th>/span>Per-EC</th> <th>Per-OT</th>
</tr>/span>
</thead>/span>
<tbody>/span>
<?php
$html = ''。
foreach($report as $key => $row1){?>
<?php foreach($row1 as $row){
$Call = $row['Call'];
$vsc = ceil(($row['EC']*100)/$Call);
$RO = $row['RO'];
$vsr = ceil(($row['OT']*100)/$RO)。
?">。
<tr>
<?php if($key !=$html){?
?>。
<td rowspan="<?php echo count($report[$key]); ? >">
<?php echo $key ? ></td>
<?php }
$html =$key;
?">。
<td><small> < ? =$row['NAMA_SGRUP']?></small></td>/span>
<td><?=$row['EC']? ></td>/span>
<td><?php if($vsc >=100){echo '100%'; }else{echo $vsc. '%';}?></td>
<td><?=$row['OT']? ></td>/span>
<td><?php if($vsr >=100){echo '100%'; }else{echo $vsr. '%';}?></td>?
<td><?=$row['Ratio']? ></td>/span>
<td><?=number_format($row['SBQ'])? ></td>
<td><?=ceil($row['SBQ']/$row['EC'])? ></td>/span>
<td><?=ceil($row['SBQ']/$row['OT'])? ></td>/span>
</tr>/span>
<?php }?>
<?php }?>
</tbody>
</body>
</html>/span>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/311035.html
標籤:
上一篇:CI驗證帶有特殊字符的請求
下一篇:編輯插入的表sql
