Php + mysql output problems

Source: Internet
Author: User
Php + mysql output question Field 1 field 2

Big classification 1 small classification 1

Big classification 1 small Classification 2

How can I use php + mysql to output the following content for the above database tables?









Big classification 1

Small Category 1

Sub-category 2


Reply to discussion (solution)

This post was last edited by ss86965921ss at 19:30:05

Field 1 field 2

Big classification 1 small classification 1

Big classification 1 small Classification 2

How can I use php + mysql to output the following content for the above database tables?


Big classification 1

Small Category 1

Sub-category 2

......

// The first is MYSQL Query. Only SQL statements are written here.
$ SQL = "select field 1, field 2 from table name where condition ";
$ Result = $ mysqli-> query ($ SQL );
// Obtain the matching records and assign them to a variable.
$ Rs1 = $ result-> fetch_assoc ();
$ Rs2 = $ result-> fetch_assoc ();
// Then output
Echo"

". $ Rs1 ['Field 1']."

". $ Rs1 ['Field 2']."

". $ Rs2 ['Field 2']."

";

How do I output big Classification 2?

How do I output big Classification 2?

Big classification 1

Small Category 1

Sub-category 2

Big Classification 2

Small Category 1

Sub-category 2

The method on the second floor is not feasible. if it is to be added later, it cannot be generated.

$ Rs = mysql_query ('select * from table order by 1, 2'); $ last = ''; echo'

'; Where ($ r = mysql_fetch ($ rs) {if ($ r ['Field 1']! = $ Last) {echo"

{$ R ['Field 1']}

"; $ Last = $ r ['Field 1'];} echo"

{$ R ['Field 2']}

";}

I don't feel wrong.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.