我現在的問題是如何循環 通過數據從 數據庫未來的陣列組,以顯示 說幾萬。
您的類別如何組織?我假設你有一個你想要組織的單一「類別」列。並且您已使用ORDER BY在查詢中對其進行了排序。
然後假設你有這些排序行的一組,你可以跟蹤,當該類別改變組織爲數組的數組
$currCat = "NotaNumber";
$output = "";
while ($row = mysql_fetch_row($queryRes))
{
# when the category changes, add closing and opening ul's
# we'll trim the excess </ul> and <ul> off later
# You can change this to also limit the number printed
# by combining with the other answer
if ($row['categoryColumn'] != $currCat)
{
$output .= "</ul>";
$output .= "<ul>";
$currCat = $row['categoryColumn'];
}
$output .= "<li> Category No: " . $row['categoryColumn'] .
" Data:" . $row['catData'] . "</li>";
}
# Trim </ul> from front and <ul> from back by getting a substring
$output = substr($output, 5, strlen($output) - 9);
echo $output
原來的答覆
印刷類:
function printCategories($catItems)
{
echo "<ul>";
$numPrinted = 0;
foreach ($catItems as $catItem)
{
echo "<li> $catEntry </li>"
$numPrinted++;
if ($numPrinted > 10)
{
break;
}
}
echo "</ul>";
}
foreach ($categories as $category)
{
printCategories($category);
}
你已經有一些PHP代碼?如果有,請顯示卡住的位置。 – 2011-04-26 15:53:22
我的php代碼目前的行爲與@Doug T發佈的代碼類似,代碼如下 – 2011-04-26 16:01:42
您的意思是說前10個「項目」將顯示在第一個列表中? – 2011-04-26 16:14:04