0

我的数据库示例是这样的

database:test
table:test

id  name  password   message  active
1   test  testpass   testmsg   no
2   test2 testtest   testmsg2  no

当我运行 sql 查询并在 php 中显示它时,它只给出一个结果。php部分是,

$a=mysqli_query($con,"select name from test where active='no'");
$b=mysqli_fetch_array($a);
print_r($b);

它只显示了第一条记录

test

有人可以建议我,我在哪里做错了吗?

4

4 回答 4

2

使用 while 循环遍历所有记录

$a=mysqli_query($con,"select name from test where active='no'");
while($b=mysqli_fetch_array($a))
print_r($b);
于 2013-06-26T09:18:40.427 回答
2

这是 PHP 的期望行为。您应该在循环中获取行,如下所示:

$result = mysqli_query($con,"select name from test where active='no'");
while ($row = mysqli_fetch_array($result))
{
    print_r($row);
}
于 2013-06-26T09:19:43.040 回答
0

尝试这个:

echo "<pre>";
print_r($b);
echo "</pre>";
于 2013-06-26T09:18:42.927 回答
0

您必须使用循环获取结果:

$b = mysql_fetch_array($query)

foreach($b as $b)
{
  echo $b[];
]
于 2013-06-26T09:25:52.083 回答