0

我有一个通过文本文件用 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] . "  &deg;</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>";
4

2 回答 2

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>
于 2013-07-11T03:27:11.110 回答
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] . "  &deg;</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){
  ...
}

然后这将循环遍历每个值,而无需知道最大计数

于 2013-07-11T04:37:03.860 回答