Php loop output how to implement the same value of a field to be output only once

Source: Internet
Author: User
Php loop output how to achieve the same value under a field only output one data table at a time student Field is id name age
There are 1, 3, and 18 values in the field.
2 Li Si 17
3 Wang Wu 18
4 Li Si 17
I want to output a table cyclically in php
However, the name of Li Si is output only once.









Name Age

To achieve this

Name age
Zhang San 18

Name age
Li Si 17
Li Si 17

Name age
Wang Wu 18

$ SQL = mysql_query ('select distinct name from student ');
While ($ row = mysql_fetch_array ($ SQL )){









Name Age

}
If $ row ['age'] cannot be written in this way, how to implement php? thank you!


Reply to discussion (solution)

$ SQL = mysql_query ('select distinct name, age from student ');

Select distinct name from student
Change
Select distinct name, age from student

$ SQL = mysql_query ('select distinct name, age from student ');



Are there other methods?

Select distinct name from student
Change
Select distinct name, age from student



This method does not work
Select *, count (distinct name) from student group by name can be implemented, but thank you.

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.