我想要生成前10個標籤,我認爲它非常簡單。PHP/SQL腳本不能正常工作
//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] = $topArray[1] + 1;
}
if($poland["tagID"] == 2)
{
$topArray[1] = $topArray[2] + 1;
}
if($poland["tagID"] == 3)
{
$topArray[2] = $topArray[3] + 1;
}
if($poland["tagID"] == 4)
{
$topArray[3] = $topArray[4] + 1;
}
}
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;
}
}
}
我遇到的唯一問題是,它認爲我在某個地方的代碼有語法錯誤,但無論哪條線路我省略了語法錯誤停留。
此外,有沒有一種更簡單的方法來做我的if語句爲10個不同的陣列點,而不是四個?
也是,看着模式,你可以只使用$ topArray [($波蘭[「標籤識別「] - 1)] = $ topArray [$ poland [」tagID「]] + 1; – optimistAk 2011-02-18 02:01:30