php迴圈輸出怎麼實現一個欄位下相同值只輸出一次

來源:互聯網
上載者:User
有一個資料表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 這個才能實現 不過還是謝謝
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.