douguazhi5966 2019-05-04 05: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 06: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部