我已經加入多個表與INNER JOIN,並得到它類似於這樣的輸出:顯示類別結果
SPORT COUNTRY LEAGUE MATCH
SPORT COUNTRY LEAGUE MATCH
SPORT COUNTRY LEAGUE MATCH
我想SPORT要顯示只在第一次它在查詢中發現的。與COUNTRY和LEAGUE一樣,所以它們作爲比賽的頭部。就像這樣:
SPORT
COUNTRY
LEAGUE1
MATCH
MATCH
MATCH
LEAGUE2
MATCH
MATCH
MATCH
代碼:
if ($db_found) {
$SQL ="
select sportname,
tournament_templatename,
tournament_stagename,
GROUP_CONCAT(eventname) as event_name
from ('SELECT
event.id AS eventid,
event.name AS eventname,
event.tournament_stageFK AS eventtournamentstageFK,
event.startdate AS eventstartdate,
tournament_stage.id AS tournament_stageid,
tournament_stage.name AS tournament_stagename,
tournament_stage.tournamentFK AS tournament_stagetournamentFK,
tournament.id AS tournamentid,
tournament.name AS tournamentname,
tournament.tournament_templateFK AS tournamenttournament_templateFK,
tournament_template.id AS tournamenttemplateid,
tournament_template.name AS tournament_templatename,
tournament_template.sportFK AS tournament_templatesportFK,
sport.id AS sportid,
sport.name AS sportname
FROM event
INNER JOIN tournament_stage
ON event.tournament_stageFK=tournament_stage.id
INNER JOIN tournament
ON tournament_stage.tournamentFK=tournament.id
INNER JOIN tournament_template
ON tournament.tournament_templateFK=tournament_template.id
INNER JOIN sport
ON tournament_template.sportFK=sport.id
WHERE
DATE(event.startdate) = CURRENT_DATE()
ORDER BY
sport.id ASC, tournament_template.name ASC, event.startdate ASC'
)
GROUP BY
sportname, tournament_templatename, tournament_stagename
ORDER BY
sportname, tournament_templatename, tournament_stagename";
$result = mysql_query($SQL);
echo "<table border='1' style='border-collapse: collapse;border-color: white;
font-size:8px; background-color: #c8ccce; width:100%;'>";
while($db_field=mysql_fetch_assoc($result)){
echo "<tr>" , "<td>" , $db_field['sportname'] , "</td> " , "<td>" ,
$db_field['tournament_templatename'] , "</td>" , "<td>" ,
$db_field['tournament_stagename'] , "</td>" , "<td>" , $db_field['eventstartdate'] ,
"</td>" , "<td>" , $db_field['eventname'] , "</td>" , "</tr>";
}
echo "</table>";
mysql_close($db_handle);
}
感謝您的幫助了PHP新手。
請league1,league2更新您的輸入表。並指定RDMS:(MySQL,Oracle等)。和你的查詢產生的結果。 – 2011-12-29 17:43:50
我不知道查詢中的哪些列對應的4列(運動,國家,聯盟,比賽)。 – 2011-12-29 18:30:03
sport is sport.name,國家是tournament_template.name,聯賽是tournament_stage.name,比賽是event.name。這是你問的嗎? – 2011-12-29 18:51:33