簡體   English   中英

如何使用固定標題和來自mysql的表格內容使表格可滾動

[英]how to make the table scrollable with fixed header and the table content from mysql

如何使此表可滾動? 我嘗試了不同的代碼,但我總是在這一行遇到問題: $avaya=mysql_query("SELECT * From avaya_pabx"); . 當我回顯<td>時,我使用的其他代碼有問題。

這是我的代碼:

<div id="pageContent">

<title>Avaya PABX</title>
<table class='hovertable'>
<tr>
<th width="31">---</th>
<th width="12%">Critical Spare ID</th>
<th width="11%">Serial No.</th>
<th width="8%">Comcode</th>
<th width="9%">Version</th>
<th width="12%">Circuit Pack</th>
<th width="13%">Classification</th>
<th width="8%">Location</th>
<th width="12%">Availability</th>
<th width="5%">Date</th>
<th width="7%">Client</th>
</tr>

<?php

$avaya=mysql_query("SELECT * From avaya_pabx");

$alternate=0;

while ($row=mysql_fetch_array($avaya))
{
$alternate++;
if ($alternate==3)
$alternate=1;
echo "<tr class=class$alternate onmouseover=\"this.style.backgroundColor='#ffff66';\"          onmouseout=\"this.style.backgroundColor='#d4e3e5';\">";
echo "<td><font size=1><a href='deleteavaya.php?serial_no=" . $row['serial_no'] . "' onclick=\"return confirmdelete('$row[serial_no]')\">[Delete]</a></font></td>";
echo "<td>" . $row['critical_spare_id'] . "</td>";
echo "<td>" . $row['serial_no'] . "</td>";
echo "<td>" . $row['comcode'] . "</td>";
echo "<td>" . $row['version'] . "</td>";
echo "<td>" . $row['circuit_pack'] . "</td>";
echo "<td>" . $row['classification'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['availability'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['client'] . "</td>";
}

?>
</table>

<style>
#pageContent 
{
    width:100%;
    height:18cm;
    overflow:scroll;
}
</style>

將表內容回顯到 div 內的新表中,該表應用了以下 css:

width:auto; /* or what you need it to be */
height: 500px; /* make this the size you want the data to be displayed in */
overflow: auto; /* this adds the scroll bars to the div when any data exceeds its hieght */

您只需要添加

table tbody{
  display: block;
  height: 150px;
  overflow-x: auto;
  overflow-y: scroll;
}

height添加您需要的默認值

暫無
暫無

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

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