How to implement a category to do a title, below the title shows some field content under that category
It should be done with nested loops, but I've cycled a couple of times and it's all wrong, and it could be that the outer loop and the inner loop are repeating:
PHP Code
$result = mysql_query ("Select P_class from product group by P_class limit 40");//Get Product category name: P_class Mysql_data_seek ($result , 0); while ($row =mysql_fetch_row ($result)) {echo "
'; echo "$row [$i]"; Echo '; $result 2 = mysql_query ("select * from Product where p_class= $row [$i] Limit 0,4"); while ($row =mysql_fetch_row ($result 2)) {echo '
\ n "; echo "
\ n "; for ($i =0; $i
'; for ($i =0; $i < td=""> |
'; }//outer Loop End} echo "\ n "; } echo "\ n "; mysql_free_result ($result); Mysql_close ($conn);? >
------Solution--------------------
There is no mistake in thinking, the code is basically correct
But there's something wrong with your HTML code.
Your inner table, written outside the outer table marker, naturally looks like a mess.
------Solution--------------------
For reference only:
SQL code
mysql> select * from csdn_test4;+----+--------+--- -------------------+| ID | Type | Content |+----+--------+----------------------+| 1 | Astronomy | Astronomical Astronomical Astronomy | | 2 | Astronomy | Daily Astronomy | | 3 | Astronomy | Wen Tian Astronomy | | 4 | Geography | Geographical Geographic Geography | | 5 | Geography | Ground to Ground | | 6 | Geography | Taken Care | | 7 | Technology | Science and Technology Technology | | 8 | Technology | Cococo | | 9 | Technology | Technical and technical |+----+--------+----------------------+9 rows in Set (0.00 sec)
------Solution--------------------
Discussion
Thank you so much.
But I really do not understand, because there are many changes to the layout, such as the number of fields in my data table is a lot, this page needs to display the knowledge of two or three fields.
I don't know how to change it.