嗨,我尝试列出以首字母分隔的类别,但我混淆了如何使用 ul 和 li 设置样式,这是我的查询
$Sql = "SELECT *, COUNT(Cup_Id) AS num
FROM tabcup
INNER JOIN tabcats ON tabcupom.Cat_Id = tabcats.Cat_Id
WHERE tabcup.Cup_Status = 1
GROUP BY tabcup.Cat_Id
ORDER BY tabcat.Cat_Nome
";
$Query= mysql_query($Sql, $Conn) or die (mysql_error($Conn));
while($Rs = mysql_fetch_assoc($Query)){
if($initial !== strtoupper(substr($Rs['Cat_Nome'], 0, 1))) {
$initial = strtoupper(substr($Rs['Cat_Nome'], 0, 1));
$Cats .= "<h2>$initial</h2>\n";
}
$Cats .= "<li>".$Rs["Cat_Nome"]." (".$Rs["num"].")</li>\n";
}
echo $Cats;
这返回
<h2> A </h2>
<li> Aaaaaa</li>
<li> Abbbb</li>
<h2> B </h2>
<li> Baaaaa</li>
<li> Bbbbb</li>
我尝试的结果是
<h2> A </h2>
<ul>
<li> Aaaaaa</li>
<li> Abbbb</li>
</ul>
<h2> B </h2>
<ul>
<li> Baaaaa</li>
<li> Bbbbb</li>
</ul>
谢谢你的帮助