<?php
$mysqli=new?mysqli('localhost','root','','tamia');
$mysqli->set_charset('utf8');
if($mysqli->connect_errno){
????die('CONNECT?ERROR:'.$mysqli->connect_error);
}
$sql="SELECT?id,usernam,age?FROM?users";
$mysqli_result=$mysqli->query($sql);
if($mysqli_result?&&?$mysqli_result->num_rows>0){
????while($row=$mysqli_result->fetch_assoc()){
????????$rows[]=$row;
????}
}
?>
<!DOCTYPE?html>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
????<title>Document</title>
</head>
<body>
<h2></h2>
<table?border="1"?cellpadding="0"?cellspacing="0"?width="80%"?bgcolor="#ABCDEF">
????<tr>
????????<td>編號</td>
????????<td>用戶名</td>
????????<td>年齡</td>
????</tr>
????????<<?php?$i=1?foreach($rows?as?$row):?>
????<tr>
????????<td><?php?echo?$i;?></td>
????????<td><?php?echo?$row['username'];?></td>
????????<td><?php?echo?$row['age'];?></td>
????</tr>
????????<?php?endforeach?>
</table>
</body>
</html>?按照老師的些的,提示29行語法錯誤哇,
1 回答

eeerrr
TA貢獻1條經驗 獲得超2個贊
<<?php?$i=1?foreach($rows?as?$row):?> 問題如下: 1,行首多了個< 2,$i=1后沒有加分號 <?php?$i=1;?foreach($rows?as?$row):?>
自己找到問題原因了。
總結一下,基本上自己都是可以找到原因的,只是在出錯的時候可能不大容易找到問題所在——這是一種心理驅使。
不妨先把問題放一放,過一會再找,或者等到第二天一看,就全然明白了。
- 1 回答
- 0 關注
- 2555 瀏覽
添加回答
舉報
0/150
提交
取消