0

查询运行以显示记录的记录输出存在问题......它只显示代码指定的第一行,然后下一个结果全部显示在......段落中?不知道是不是有事

<?php
include 'core/init.php';
include 'includes/overall/header.php';
?>
<div class="article" style="width:900px !important">
<?php

$result = $sql = mysql_query("SELECT * FROM ref_employees WHERE employerid={$user_data['user_id']} ")
   or die('Error in query : $sql. ' .mysql_error());
      echo "<table border='0' class='table'>
<tr>
<th>ID Number</th>
<th>Employee Number</th>
<th>FirstName</th>
<th>LastName</th>
<th>MiddleName</th>
<th>Job Title</th>
<th>Employement Status</th>
<th>Contact</th>
<th>Email</th>
<th>Edit</th>
</tr>";

if (mysql_num_rows($sql) > 0) 
{            


while ($row = mysql_fetch_array($sql)){

    if ($row['employed'] == '1'){

 echo "<tr>";
    echo "<td>" . $row['idnumber'] . "</td>";
    echo "<td>" . $row['empnumber'] . "</td>";
    echo "<td>" . $row['firstname'] . "</td>";
    echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['middlename'] . "</td>";
    echo "<td>" . $row['jobtitle'] . "</td>";
    echo "<td>" . $row['employed'] . "</td>";
    echo "<td>" . $row['contactnum'] . "</td>";
    echo "<td>" . $row['contactemail'] . "</td>";
    echo "<td>" . $row['FirstName'] . "</td>";
     echo "</tr>";
  echo "</tr>";
  echo "</table>";
  }



   } 
}

?>
</div>

<?php include 'includes/overall/footer.php';

?>
4

1 回答 1

1

您正在使用关闭表标签进入循环

while ($row = mysql_fetch_array($sql)){
    ....
    ....
    ...
    echo "</table>";
}

在循环外使用表结束标记作为

while ($row = mysql_fetch_array($sql)){
    ....
    ....
    ...
}
echo "</table>";
于 2013-09-22T15:02:54.410 回答