以下是代码:
<?php
//Starting session
session_start();
//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs
require_once ('includes/mass.php');
$username = $_SESSION['username'];
if (isset($username))
{
//Query database for the users networths
$sq_l = "SELECT * FROM user";
$sql_query_worth = mysql_query($sq_l);
while ($row = mysql_fetch_assoc($sql_query_worth))
{
$dbusername = $row['username'];
}
echo $dbusername;
}
?>
答案 0 :(得分:11)
你在循环之外回应。所以它只是回应最后一排。将echo语句放在while循环中。
答案 1 :(得分:2)
如果要打印所有用户名,则echo语句应该在while循环中,例如。
while ($row = mysql_fetch_assoc($sql_query_worth))
{
$dbusername = $row['username'];
echo $dbusername;
}
答案 2 :(得分:2)
您正在使用此部分代码:
while ($row = mysql_fetch_assoc($sql_query_worth))
{
$dbusername = $row['username'];
}
echo $dbusername;
这意味着只有最后一位用户的姓名为echo
:
$dbusername
$row['username']
的最后一个值。
如果你想输出每个用户名,你应该把echo
放在循环中,而不是在:
while ($row = mysql_fetch_assoc($sql_query_worth))
{
$dbusername = $row['username'];
echo $dbusername . '<br />';
}
然后,每个用户的每个名字都应该echo
; - )