簡體   English   中英

如何為從PHP數組獲取的表制作滾動視圖

[英]How to make a scroll view for table acquired from php array

我有這個多維數組$array2 ,它顯示如下(這只是數組的一部分,它包含1000多個元素)

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)

我已經設法使用代碼從中創建了一個表

<?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;
?>

上面的代碼顯示所有表記錄,而我期望的是一個滾動視圖表,該表僅顯示10條記錄/行。

您需要使用DIV並將table放在div中,例如:

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

OR

您可以在CSS中創建一個類

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

在div中使用此類

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

您可以隨心所欲放置height

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM