Home  >  Article  >  Backend Development  >  如何实现类别做标题,标题上面显示该类别上的某些字段内容

如何实现类别做标题,标题上面显示该类别上的某些字段内容

WBOY
WBOYOriginal
2016-06-13 10:34:54780browse

怎么实现类别做标题,标题下面显示该类别下的某些字段内容
应该是用嵌套循环来实现,但是我自己循环了几次,都是错误的,可能是外循环和内循环重复了:

PHP code
<!--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 "
\n"; echo "\n"; for ($i=0; $i'; echo "$row[$i]"; echo ''; $result2 = mysql_query("SELECT * FROM Product where p_class=$row[$i] limit 0,4"); while ($row=mysql_fetch_row($result2)) { echo '
'; for ($i=0; $i"; }//内循环结束 echo '
'; }//外循环结束 } echo " \n"; } echo "\n";mysql_free_result($result);mysql_close($conn);?>




------解决方案--------------------
思路没有错,代码也基本正确
不过你的html代码有问题
你内层的表格,写在外层表格标记的外边,自然就看着乱七八糟了
------解决方案--------------------
仅供参考:
SQL code
mysql> 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>
探讨
太感激你了。
但是我真的看不懂,因为还有很多要修改的排版,比如我的数据表内字段数量是很多,这个页面需要显示的知识两三个字段。我不知道怎么修改了。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn