gpt4 book ai didi

php - 带有 foreach 循环的样式表

转载 作者:行者123 更新时间:2023-11-28 07:52:54 24 4
gpt4 key购买 nike

我有一个包含 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>

好像是display:block;导致了这个问题。但是我还能如何添加卷轴呢?

tbody{
display: block;
overflow-y:auto;
overflow-x: hidden;
height: 100px;
width: 100%;
}

最佳答案

我认为,您应该移出第二个 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>';
}

关于php - 带有 foreach 循环的样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30285201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com