我有一个通过文本文件填充php的表。我知道如何为每个新数据条目创建一个新表,但我试图创建一个新行而不是一个全新的表。如何使用数据而不是整个表创建新行?
这是我现在所拥有的,我只想创建一个包含变量的新行。如果没有每次创建一个全新的表,我怎么能实现这个目标。我尝试了一些没有成功的事情。
$tracreport = $tracreport . "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'>
<tr>
<td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active storm cell</td>
</tr>
<tr>
<td>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td>
<table id='tracReport' width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td
</tr>
<tr>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td>
</tr>
</table>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>";
答案 0 :(得分:0)
使用此方法生成表格行:
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<?php
$yourquery = mysql_query("");
while ($rows = mysql_fetch_assoc($yourquery)) {
?>
<tr>
<td><?php $rows['name']; ?></td>
<td><?php $rows['age']; ?></td>
</tr>
<?php } ?>
</table>
答案 1 :(得分:0)
您可以尝试拆分表格,然后在中间添加循环
// begin your table
$tracreport = $tracreport . "<table width='100%' cellpadding='0' cellspacing='0' style='margin-top:15px; background-color:#000; color:#FFF;'>
<tr>
<td style='padding: 3px 0px 3px 0px; font-size: .9em; text-align: center; color: #00FF00;'> Tracking " . $tnumber[1] . " active storm cell</td>
</tr>
<tr>
<td>
<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td>
<table id='tracReport' width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Cell ID</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Tracking Since</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Bearing</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Distance</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Intensity</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Trend</td>
<td style='background-color:#333; color:#3299cc; font-weight: normal; border: 1px #666 solid; text-align: center; font-size: .9em;'>Last Strike</td
</tr>"; // break the top part of the table
// create your loop
for($k=0;$k<YOUR MAX ROWS;$k++){
$tracreport .="<tr>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tid[$k] . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdtime[$k] . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdirection[$k] . " °</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . $tdistance[$k] . " miles</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . strtolower($tintensity[$k]) . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($ttrend[$k])) . "</td>
<td style='background-color: black; color: #FFF; border: 1px #666 solid; text-align: center; font-size: .9em;'>" . trim(strtolower($tactivity[$k])) . "</td>
</tr>";
} // close your loop
// finish your table
$tracreport .= "</table>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>";
修改强>
而不是for($k=0;$k<YOUR MAX ROWS;$k++){...}
,如果您不知道总的最大值,请使用foreach循环
foreach($tid as $k => $v){
...
}
这将循环遍历每个值,而无需知道最大计数