我有以下代碼:PHP foreach循環問題
//generate 10 top tags
$tagSQL = mysql_fetch_array(mysql_query("SELECT * FROM tags"));
$topArray = array();
foreach($tagSQL as $poland)
{
if($poland["tagID"] == 1)
{
$topArray[0] ++;
}
if($poland["tagID"] == 2)
{
$topArray[1] ++;
}
if($poland["tagID"] == 3)
{
$topArray[2] ++;
}
if($poland["tagID"] == 4)
{
$topArray[3] ++;
}
}
function printTopTags()
{
$n = 0;
foreach($topArray as $buddha)
{
$n = $n + 1;
if(sizeOf($topArray) > $n)
{
$hersheyBar = " ";
}
else
{
$hersheyBar = "";
}
$finalFinalEndArray = mysql_fetch_array(mysql_query("SELECT tagName FROM tags WHERE tagID = '$buddha'"));
foreach($finalFinalEndArray as $waterBottle)
{
echo $waterBottle . $hersheyBar;
}
}
}
我得到的錯誤Warning: Invalid argument supplied for foreach() on line 93
93號線是foreach($topArray as $buddha)
。
任何幫助?
`的var_dump($ topArray);`PS:你問了幾個瑣碎的問題連續幾周。爲新手閱讀一些PHP書不是更簡單嗎? – zerkms 2011-02-18 05:17:57