2014-12-03 36 views
-1

嗨,大家我一直在网上搜索,但没有什么来拯救。我有代码生成表。我有的问题是代码显示所有在一个页面中的列,我希望它只显示10列,其余列显示到下一页,如果列仍然超过10,只显示10,并将剩余的下一页。这里是什么 我到目前为止。我的输出如下如何将剩余的列移动到PHP中的下一页

reg | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34

我需要像

REG | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

REG | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20

REG | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30

reg | 31 | 32 | 33 | 34

这是我的代码。

foreach($trips as $key => $element){ 
    $out .= "<tr>"; 

    $out .= "<td>$key</td>"; 
    foreach($element as $subkey => $subelement){ 

    $out .= "<td >$subelement</td>"; 

    } } $out .= "</tr>"; 

    } 
    $out .= "</table>"; 
    print $out; 
+0

无处在你的代码,你有什么企图限制的东西? – PeeHaa 2014-12-03 11:12:05

+0

如果数组数据来自数据库,那么你可以使用分页 – 2014-12-03 11:12:19

+0

在你的SQL查询中用'LIMIT 10 OFFSET ###'尝试一些操作。这就是所谓的分页。 – Justinas 2014-12-03 11:15:28

回答

0

我终于找到了解决方案,以打破下来只用PHP的

$tripIds = array_unique($tripIds); 
$tripChunks = array_chunk($tripIds,$parameterChunk); 

foreach($tripChunks as $tripChunk): 

$out = ""; $out .= "<table>"; 

// td padding for station name 
$out .= "<td style='width:123px;padding:0px 15.5px 0px 9.8px;border: 10px solid transparent;  color:red;background-color: #DBDBDB;page-break-inside:avoid; page-break-after:auto;'></td>"; 


foreach ($tripIds as $keys=>$value): 

if(!in_array($value, $tripChunk)) continue; 

$out .= "<td style='width:123px;padding:0px 15.5px 0px 9.8px;border: 10px solid transparent; color:red;background-color: #DBDBDB;page-break-inside:avoid; page-break-after:auto;'>$value</td>"; 
$counter++; 

endforeach; 
$i=0; 

foreach ($newArray as $keys=>$value): 

$out_temp = "<tr>"; 

$out_temp .= "<td style='padding:0px 0px 0px 0px;page-break-inside:avoid; page-break-after:auto;'>$keys</td>"; 
foreach ($value as $index=>$valu2): 

if(!in_array($index, $tripChunk)) 
    continue; 
else 
{ 
    $out .= $out_temp; 
    $out_temp = ""; 
} 

$out .= "<td style='padding:0px 4px 0px 5px;page-break-inside:avoid; page-break- after:auto;'>$valu2</td>"; 
endforeach; 

$out .= "</tr>"; 
endforeach; 


    $out .= "</table>"; 
    print $out; 

    endforeach; //tripchunk 
相关问题