我有一个包含8列的表,然后运行foreach循环以显示表中的所有内容。 我想用滚动条为表格设置样式,以便标题保持粘性,但如果我添加所有内容,则只显示第一列(日期)的标题下。 如何为表格添加样式,同时确保内容显示在正确的列中?
<table id="email_subscription">
<thead>
<tr>
<th>Date</th>
<th>c1</th>
<th>c2</th>
<th>c3</th>
<th>c4</th>
<th>c5</th>
<th>Total New</th>
<th>All Contacts</th>
</tr>
</thread>
<tbody>
<?php
foreach($values as $v_date){
$date = $v_date->DATE;
$count = $wpdb->get_results($wpdb->prepare(
" SELECT DISTINCT `date`.... ",
echo '<tr class="row_main">';
echo '<td>' . $date . '</td>';
foreach($count as $counts){
$val1 = $counts->c1;
$val2 = $counts->c2;
$val3 = $counts->c3;
$val3a = $counts->c4;
$val3b = $counts->c5;
$val9 = $counts->all_contacts;
echo '<td>' . $val1 . '</td>';
echo '<td>' . $val2 . '</td>';
echo '<td>' . $val3 . '</td>';
echo '<td>' . $val3a . '</td>';
echo '<td>' . $val3b . '</td>';
echo '<td>' . $val7 . '</td>';
echo '<td>' . $val9 . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
似乎显示:块;造成了这个问题。但是我怎么添加滚动?
tbody{
display: block;
overflow-y:auto;
overflow-x: hidden;
height: 100px;
width: 100%;
}
答案 0 :(得分:0)
我认为,你应该走出第二个foreach循环以完成一行:
foreach($count as $counts){
$val1 = $counts->c1;
$val2 = $counts->c2;
$val3 = $counts->c3;
$val3a = $counts->c4;
$val3b = $counts->c5;
$val9 = $counts->all_contacts;
echo '<td>' . $val1 . '</td>';
echo '<td>' . $val2 . '</td>';
echo '<td>' . $val3 . '</td>';
echo '<td>' . $val3a . '</td>';
echo '<td>' . $val3b . '</td>';
echo '<td>' . $val7 . '</td>';
echo '<td>' . $val9 . '</td>';
}
echo '</tr>';
}