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.

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

报告相同问题?

悬赏问题

  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动
  • ¥15 大一C语言期末考试,求帮助🙏🙏
  • ¥15 ch340驱动未分配COM
  • ¥15 Converting circular structure to JSON
  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader
  • ¥45 谷歌浏览器出现开发者工具无法显示已创建的,但您可以调试已部署的代码。 状态代码 404, net::ERR HTTP RESPONSE CODE FAILURE
  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程