我试图显示数据库中所有用户的信息并且不断给我这个错误
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in /home/killerdu/public_html/userlist.php on line 30
第30行
while($people=mysql_fetch_assoc($people_list)){
<?php
include 'core/int.php';
include 'includes/head.php';
include 'head.php';
include 'includes/body.php';
include 'body.php';
$people_list="SELECT * FROM users";
$people=mysql_query($people_list);
?>
<html>
<head>
</head>
<body>
<pre>
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
</tr>
<?php
while($people=mysql_fetch_assoc($people_list)){
echo "<tr>";
echo "<td>". $people_list['user_id']."</td>";
echo "<td>". $people_list['username']."</td>";
echo "<td>". $people_list['email']."</td>";
echo "</tr>";
}
?>
</thead>
</pre>
</body>
</html>
答案 0 :(得分:3)
根据OP的要求,回答评论:
您混合了while($people=mysql_fetch_assoc($people_list))
变量的变量。 while($people_list=mysql_fetch_assoc($people))
答案 1 :(得分:2)
您使用了$people=mysql_query($people_list);
所以加载它:
while($row=mysql_fetch_assoc($people)) {
// ^ load $people, the resource, not $people_list the string
您加载了查询字符串而不是资源。