我现在的问题是如何循环 通过数据从 数据库未来的阵列组,以显示 说几万。
您的类别如何组织?我假设你有一个你想要组织的单一“类别”列。并且您已使用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