显示保存在数据库中的所有用户名

时间:2014-12-15 12:00:01

标签: php

所以我想知道如何显示当前保存在我的数据库中的所有用户名?

我目前仍然只显示1个用户名

感谢您的帮助。

<?php

 $con = new mysqli("blank", "blank", "blank", "blank");


$result = mysqli_query($con,"SELECT * FROM users WHERE user_id > '0'");
$row = mysqli_fetch_array($result);



echo $row['username'];
?>

2 个答案:

答案 0 :(得分:1)

$con = new mysqli("blank", "blank", "blank", "blank");

$result = mysqli_query($con,"SELECT * FROM users WHERE user_id > 0");
while ( $row = mysqli_fetch_assoc ( $result ) ) {
    echo $row [ 'username' ] ."<br />";
}

这只不过是循环你的结果。

答案 1 :(得分:0)

        <?php

     $con = new mysqli("blank", "blank", "blank", "blank");


    $result = mysqli_query($con,"SELECT * FROM users WHERE user_id > '0'");
    $row = mysqli_fetch_array($result);

    while($row = mysqli_fetch_array($result)){
    foreach($row as $rs){
echo $rs['name']
}
    }


    ?>

试试这个