输出不显示所有行

时间:2013-09-22 14:54:11

标签: php

从查询运行的记录输出出现问题以显示记录....它只显示代码指定的第一行,然后显示所有..段落中的下一个结果?我不知道它是否有事可做

<?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';

?>

1 个答案:

答案 0 :(得分:1)

您正在将关闭表标记用作循环

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

将表格结束标记用作循环

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