2016-05-14 10 views
0

我在<?php endwhile; ?>行發生錯誤。我的PHP電話簿CRUD項目出現錯誤

錯誤:

Parse error: syntax error, unexpected 'endwhile' (T_ENDWHILE);

代碼:

$result = mysqli_query($connect,"SELECT* FROM contacts"); 
    ?> 

    <table width="800" cellpadding="10" cellspacing="5" border="2"> 
     <tr> 
      <th>First Name</th> 
      <th>Last Name</th> 
      <th>Contact No</th> 
      <th>Email</th> 
     </tr> 
    <?php while ($row = mysqli_fetch_array($result)); ?> 
     <tr> 
      <td><?php echo $row['first_name']; ?></td> 
      <td><?php echo $row['last_name']; ?></td> 
      <td><?php echo $row['contact_no']; ?></td> 
      <td><?php echo $row['email']; ?></td> 
     </tr> 
    <?php endwhile; ?> 
    </table> 

沒有記錄顯示在表中。該頁面只是顯示錯誤。

+1

見分號在此聲明'而($行= $ mysqli_fetch_array($ result));',它應該是'while($ row = mysqli_fetch_array($ result)):' –

+0

在將'$ result'設置爲之前,您還沒有顯示初始開頭'<?php'標籤'mysqli_query'的返回。 – user221931

回答

2

如果你想使用endwhile;,您應該遵循while的病情有一個冒號(:),而不是一個分號(;):

<?php while ($row = mysqli_fetch_array($result)): ?> 
<!-- Here --------------------------------------^ >