PHP格式表头
此代码读取用于创建表的CSV文件。它很好用 如何将第一行格式化为标题样式(从CSS表中)PHP格式表头,php,csv,Php,Csv,此代码读取用于创建表的CSV文件。它很好用 如何将第一行格式化为标题样式(从CSS表中) 如果打印了第一行,但它看起来很轻,并且您希望它粗体美观,以便用户知道它是标题,请添加一个类以方便使用 table.cs-contents tr:first-child td { font-weight: bold; text-align: center; border-bottom: 2px solid #eaeaea; } 这应该行得通,我还改变了一些我认为会产生错误的marup的
如果打印了第一行,但它看起来很轻,并且您希望它粗体美观,以便用户知道它是标题,请添加一个类以方便使用
table.cs-contents tr:first-child td {
font-weight: bold;
text-align: center;
border-bottom: 2px solid #eaeaea;
}
这应该行得通,我还改变了一些我认为会产生错误的marup的其他部分
<table id="myTable" class="tablesorter animated fadeInDown">
<?php
$lines = file('graphdata/IndicForTableVsOthers.csv');
foreach ($lines as $lineNum => $line) {
$cellType = ($lineNum == 0 ? "th" : "td");
$tokens = str_getcsv($line);
if ($lineNum == 0) echo "<thead>";
if ($lineNum == 1) echo "<tbody>";
echo "<tr id=\"tr" . $lineNum . "\">";
echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";
echo "</tr>";
if ($lineNum == 0) echo "</thead>";
}
if (count($lines) > 1) echo "</tbody>";
?>
</table>
CSV文件中是否有表格标题?你的意思是,你想成为CSV的第一行作为列名吗?我在想类似的事情,但让我们注意到,他在标记内打印所有内容,标记应该在标记内谢谢,@JuanBonnett,我更正了它,还发现了一些其他错误(例如单元格的结束标记)。我没有测试代码,如果它还没有为您工作,请告诉我。现在更有意义了,我不明白为什么它不应该工作
<table id="myTable" class="tablesorter animated fadeInDown">
<?php
$lines = file('graphdata/IndicForTableVsOthers.csv');
foreach ($lines as $lineNum => $line) {
$cellType = ($lineNum == 0 ? "th" : "td");
$tokens = str_getcsv($line);
if ($lineNum == 0) echo "<thead>";
if ($lineNum == 1) echo "<tbody>";
echo "<tr id=\"tr" . $lineNum . "\">";
echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";
echo "</tr>";
if ($lineNum == 0) echo "</thead>";
}
if (count($lines) > 1) echo "</tbody>";
?>
</table>