這裏的錯誤是代碼:讓我的foreach循環
<?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;
}
}
}
?>
有三種結果。這裏是錯誤。
以下是錯誤消息:
警告:(c)中提供的foreach參數無效:\ XAMPP \ htdocs中\ Mogul公司\上線richlist.php 32
警告:無效參數提供爲的foreach ()在C:\ XAMPP \ htdocs中\ Mogul公司\上線richlist.php 32
警告:在C的foreach()提供參數無效:\ XAMPP \ htdocs中\ Mogul公司\ richlist.php在線路32
看來'$ dbusername'不是一個數組。 – Gumbo 2010-03-12 16:51:08
那是什麼「foreach」?是不是'$ dbusername''一個字符串? – kennytm 2010-03-12 16:51:57
你想完成什麼?錯誤信息很清楚,循環沒有任何意義。 – 2010-03-12 16:52:15