怎么实现类别做标题,标题下面显示该类别下的某些字段内容
应该是用嵌套循环来实现,但是我自己循环了几次,都是错误的,可能是外循环和内循环重复了:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
$result = mysql_query("SELECT p_class FROM Product group by p_class limit 40");//取得商品类别名称:p_class
mysql_data_seek($result, 0);
while ($row=mysql_fetch_row($result))
{
echo "<table bord='1'>\n";
echo "<tr>\n";
for ($i=0; $i<mysql_num_fields($result); $i++ )//外循环,实现分行显示p_class名
{
echo '<td align="center">';
echo "$row[$i]";
echo '</td>';
$result2 = mysql_query("SELECT * FROM Product where p_class=$row[$i] limit 0,4");
while ($row=mysql_fetch_row($result2))
{
echo '<table><tr><td align="right">';
for ($i=0; $i<mysql_num_fields($result2); $i++ )//内循环,实现显示:在不同的P_class下的所有商品名称,图片等内容
{
echo "@@##@@";
}//内循环结束
echo '</td></tr></table>';
}//外循环结束
}
echo "</tr>\n";
}
echo "</table>\n";
mysql_free_result($result);
mysql_close($conn);
?>
<a style="color:#f60; text-decoration:underline;" title="mysql" href="https://www.php.cn/zt/15713.html" target="_blank">mysql</a>> select * from csdn_test4; +----+--------+----------------------+ | id | type | content | +----+--------+----------------------+ | 1 | 天文 | 天文 天文 天文 | | 2 | 天文 | 天 天 天文 | | 3 | 天文 | 文 文 天文 | | 4 | 地理 | 地理 地理 地理 | | 5 | 地理 | 地 地 地 | | 6 | 地理 | 理 理 理 | | 7 | 科技 | 科技 科技 科技 | | 8 | 科技 | 科 科 科 | | 9 | 科技 | 技 技 技 | +----+--------+----------------------+ 9 rows in set (0.00 sec) <br><font color="#e78608">------解决方案--------------------</font><br>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号