我正在使用 while 在 PHP 代碼中結合 HTML 代碼進行 CRUD 操作。我希望 HTML 代碼在每次執行 while() 后重復。但它給出了錯誤:“解析錯誤:語法錯誤,第 21 行 C:\xampp\htdocs\php\index1.php 中出現意外的 '?> '”。任何人都可以解決這個問題。我已經提到了下面的代碼: <?php$con=mysqli_connect("localhost","root","","student");$sql="select * from student_php";$res=mysqli_query($con,$sql);?><table> <tr> <td>S.No</td> <td>Name</td> <td>City</td> </tr><?php while($row =mysqli_fetch_assoc($res){ ?> <tr> <td>S.No</td> <td><?php echo $row['name']?></td> <td><?php echo $row['city']?></td> </tr> <?php } ?></table>
1 回答

千巷貓影
TA貢獻1829條經驗 獲得超7個贊
你的 while 循環沒有關閉。
while($row =mysqli_fetch_assoc($res)
需要是
while($row =mysqli_fetch_assoc($res))
- 1 回答
- 0 關注
- 76 瀏覽
添加回答
舉報
0/150
提交
取消