家庭餐桌顯示輸出的兩個表中
familynumber fistname lastname 10001 A B 10002 C D 10003 E F 10004 G H
電話表
familynumber phonenumber description 10001 111 mobile 10001 222 home 10001 333 text 10002 444 text 10003 555 work 10003 666 mobile
我需要輸出
familynumber phonenumbers 10001 111, 222, 333 10002 444 10003 555, 666
我知道它可以通過如下因素代碼
完成$families = mysql_query("select * from family")
while($family = mysql_fetch_assoc($families))
{
extract($family);
echo "<td>$familynumber</td>";
echo "<td>";
$phones = mysql_query("select * from phone where familynumber = '$familynumber'");
while($phone = mysql_fetch_assoc($phones))
{
extract($phone);
echo $phonenumber . ", ";
}
echo "</td>";
}
但我需要在一個SQL查詢中輸出。
請看group_concat http://mahmudahsan.wordpress.com/2008/08/27/mysql-the-group_concat-function/ –