-1

在我的程序中,我创建了一个可滚动的表,就滚动条显示、返回正确的数据等而言,一切正常。

奇怪的是,我不知道为什么,在表的标题上方,“echo”这个词重复了 7 次,每条记录返回一个。我的代码显然有一些缺陷,但我无法找到它,感谢任何帮助

    <?php
    echo "<div class='scrollableContainer'>";
    echo "<div style=' height: 125px; width: 535px; font-size: 10px; overflow: auto;'>";
    echo "<table class='referrals scrollable'>";
    echo "<thead><tr> 
            <th class='date'>Date</th>
            <th class='name'>Student Name</th>
            <th class='email'>Email</th>
            <th class='phone'>Phone</th>
            <th class='status'>Status</th>
    echo </tr></thead>";
            $query2 = "select * from students where referred_by ='$referral_id_to_use'";
            $result2 = mysql_query($query2);

            $num_rows = mysql_num_rows($result2);
            if($num_rows>0){
                 while  ($row = mysql_fetch_array($result2))
                  {
                       extract($row);
                         $student_name=$first_name.' '.$last_name;      
                 if($current_status=1)
                     {
                        $student_status="Active";
                     }else{
                        $student_status="Inactive";
                     }
        echo "<tr>\n
              <td class='date'><div>$date_joined</div></td>
              <td class='name'><div>$student_name</div></td>
              <td class='email'><div>$emailaddress</div></td>
              <td class='phone'><div>$phone_number</div></td>   
              <td class='status'><div>$student_status</div></td>
        echo </tr>";
            }
        }       
    echo "</table>";
    echo "</div>";
    echo "</div>";
    ?>

额外的回声行再次出现在表格标题上方。

谢谢

4

2 回答 2

4

您将单词echo作为 a</td>和之间的数据</tr>

由于此处不允许使用文本,因此浏览器正在错误恢复并将其移动到允许的位置(在表格之前)。

<td class='status'><div>$student_status</div></td> echo </tr>";

从源中删除“回声”一词。

通过检查生成的 HTML,并通过验证器运行生成的 HTML,这种类型的东西更容易掌握,而不是仅仅将 PHP 与浏览器中的呈现进行比较。

于 2012-08-28T13:17:29.157 回答
2

这里是:

echo "<thead><tr> 
        <th class='date'>Date</th>
        <th class='name'>Student Name</th>
        <th class='email'>Email</th>
        <th class='phone'>Phone</th>
        <th class='status'>Status</th>
echo </tr></thead>";

最后一行。在@Quentin 的回答中也可以看到身体。

于 2012-08-28T13:17:38.610 回答