显示某些记录的结果
问题描述:
无论我尝试什么,我都已经搜索过这个并且不断收到错误。显示某些记录的结果
主要的错误,我得到的是:
mysqli_fetch_assoc()预计参数1被mysqli_result,串给出
我创造出的所有记录的页面。用户然后选择一个记录进行编辑,并将该ID传递到此页面,该页面将显示表格/表格中的所有字段。一些字段是只读的,所以不能修改。 我想要实现的是在一个表中显示结果,以便它们可以被编辑,然后发送到数据库并进行更新。我正在考虑将它发送到另一个文件进行更新,然后将它们发送回查看结果页面。
<form action = 'modify2.php' method = 'post'>
<table border="1">
<tr style="border-bottom:1px solid #000000;">
<strong>User ID</strong>
<strong>Username</strong>
<strong>Password</strong>
<strong>Email</strong>
<strong>Name</strong>
<strong>Submitted By</strong>
<strong>Memeber Since</strong>
</tr>
<?PHP
//error check to see what results are obtained
echo '<br />sql code = '.$sql.'<br/>'; // this works bot the $result
shows nothing
//die();
//fetch object array and put into a row
//while($row = mysqli_fetch_assoc($result))
while($row = mysqli_fetch_assoc($sql))
{
?>
<tr><td><label>User ID :</label></td>
<td><input type = 'text' name = 'id' id = 'id' value='<?PHP echo $row["id"];?>' readonly/></input><br /></td></tr>
<tr><td><strong>Username</strong></td>
<td><input type = 'text' name = 'username' id = 'username' value='<?PHP echo $row["username"];?>'/></input><br /></td></tr>
<tr><td><label>password :</label></td>
<td><input type = 'text' name = 'password' id = 'password' value='<?PHP echo $row["password"];?>'/></input><br /></td></tr>
<tr><td><label>email :</label></td>
<td><input type = 'text' name = 'email' id = 'email' value='<?PHP echo $row["email"];?>'/></input><br /></td></tr>
<tr><td><label>Real Name :</label></td>
<td><input type = 'text' name = 'Name' id = 'Name' value='<?PHP echo $row["Name"];?>'/></input><br /></td></tr>
<tr><td><label>submitted by :</label></td>
<td><input type = 'text' name = 'submittedby' id = 'submittedby' value='<?PHP echo $row["submittedby"];?>' readonly/></input><br /></td></tr>
<tr><td><label>trn_date :</label></td>
<td><input type = 'text' name = 'trn_date' id = 'trn_date' value='<?PHP echo $row["trn_date"];?>' readonly/></input></td></tr>
<?PHP
}
//close table here
?>
<tr><td colspan='2'><div align='center'><input type = 'submit' value ='Modify Record' name = 'submit'/></td></tr>
</form></div>
</table>
答
你需要把$result=mysqli_query($con,$sql);
首先,你可以使用
// Associative array
$row=mysqli_fetch_assoc($result);
在['mysqli_fetch_assoc()'](http://php.net/manual/en/的文档看看mysqli的-result.fetch-assoc.php)。它需要一个类型['mysqli_result()'](http://php.net/manual/en/class.mysqli-result.php)的参数,它是通过调用['mysqli_query()'](http ://php.net/manual/en/mysqli.query.php)。 – axiac