【发布时间】:2010-03-12 16:47:59
【问题描述】:
代码如下:
<?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 ORDER BY worth";
$sql_query_worth = mysql_query($sq_l);
while ($row = mysql_fetch_assoc($sql_query_worth))
{
$dbusername = $row['username'];
$dbworth = $row['worth'];
foreach ($dbusername as $dbuser)
{
echo ". USER: ".$dbuser." Has a networth of: ".$dbworth;
}
}
}
?>
有三个结果。这是错误。
这是错误信息:
警告:第 32 行 C:\xampp\htdocs\Mogul\richlist.php 中为 foreach() 提供的参数无效
警告:第 32 行 C:\xampp\htdocs\Mogul\richlist.php 中为 foreach() 提供的参数无效
警告:第 32 行 C:\xampp\htdocs\Mogul\richlist.php 中为 foreach() 提供的参数无效
【问题讨论】:
-
看来
$dbusername不是数组。 -
foreach是干什么用的? `$dbusername`` 不是字符串吗? -
你想完成什么?错误信息很清楚,循环没有任何意义。
-
是 :) 我刚刚查过了。