douguazhi5966 2019-05-04 13:55
浏览 74
已采纳

如何为从php数组获取的表创建滚动视图

I have this multidimensional array $array2 which displays as follows (This is just part of the array, it contains over 1000 elements)

Array
(
    [0] => Array
        (
            [0] => M2TYEE
            [1] => Jean
            [2] => Harvey
            [3] => London
            [4] => 0314686334
        )

    [1] => Array
        (
            [0] => E26YBE
            [1] => Tom
            [2] => Cruise
            [3] => New York
            [4] => 0635625735     
        )
    [2] => Array
        (
            [0] => M2FY3E
            [1] => Jane
            [2] => Harvey
            [3] => Berlin
            [4] => 0314346334
        )

    [3] => Array
        (
            [0] => Q53YBE
            [1] => Tom
            [2] => Howland
            [3] => New York
            [4] => 0635625735     
        )
)
(This is just part of the array, it contains over 1000 elements)

I have managed to create a table out of it using the code

<?php
$arr = array_merge([ 0 => ['ID','FIRST NAME','LAST NAME','CITY','PHONE']],$array);
$html = '<table border="1">';
foreach($arr as $row){
  $html .= '<tr>';
  foreach($row as $column){
    $html .= '<td>'.$column.'</td>';
  }
  $html .= '</tr>'; 
}
$html .= '</table>';
echo $html;
?>

The above code displays all table records and what I expected was a scroll view table which displays only 10 records/rows.

  • 写回答

1条回答 默认 最新

  • duanhuanyou6478 2019-05-04 14:03
    关注

    You need to use DIV and put the table inside the div for example :

    <div style="height:100px;overflow:scroll;"> <!-- inline-css -->
     <?php echo $html;?>
    </div>
    

    OR

    you can create a class in CSS

    .overflow-div{
      height:100px;
      overflow:scroll;
    }
    

    use this class in div

    <div class="overflow-div">
     <?php echo $html;?>
    </div>
    

    You can put the height whatever you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效