php循环输出怎么实现一个字段下相同值只输出一次

WBOY
Release: 2016-06-20 12:36:15
Original
2227 people have browsed it

有一个数据表student     字段分别是  id name age
                                          字段下值有   1   张三  18 
                                                                 2   李四  17
                                                                 3   王五  18
                                                                 4   李四  17 
我想实现在php里循环输出 table                                               
但是李四的name只输出一次   
                    


                         
                             
                             
                         
                         
                             
                             
                         
                    
名字 年龄
  
想要实现这样的

名字 年龄
张三  18

名字 年龄
李四  17
李四  17

名字 年龄
王五  18

                    $sql=mysql_query('select distinct name from student');
                     while($row=mysql_fetch_array($sql)){
                    
                         
                             
                             
                         
                         
                             
                             
                         
                    
名字 年龄
  
                    }
如果这样写  $row['age'] 获取不到    该怎么实现  php小白  大神麻烦帮忙看一下 谢谢


回复讨论(解决方案)

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

select distinct name from student
改为
select distinct name,age from student

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



还有别的方法吗

select distinct name from student
改为
select distinct name,age from student



这种方法行不通   
select *, count(distinct name) from student group by name  这个才能实现  不过还是谢谢
source:php.cn
Statement of this Website
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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!