use GROUP_CONCAT:
SELECT `group`, GROUP_CONCAT(team SEPARATOR ',') AS teams ORDER BY `group`
This will give data as:
1 A,B,C
2 D,E
3 F
You can replace the separator (,) in the teams field into rows
$tables = "";
while(...){
$tables .= "<table><tr><td> . str_replace(",","</td><td>", $data['teams']) . "</td></tr></table>";
}
echo $tables;
That's my favourite.
diafol
Keep Smiling
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57
Good spot EF:
$tables .= "<table><tr><td>" . str_replace(",","</td><td>", $data['teams']) . "</td></tr></table>";
diafol
Keep Smiling
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57
Mark thread solved (link button below) if it is.
BTW - the separator ',' - may be better to use something else as ',' may form part of a team name, if you have real names that is as opposed to just letters.
diafol
Keep Smiling
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57
I already provided you with the loop structure:
$result = mysql_query("SELECT `group`, GROUP_CONCAT(team SEPARATOR '|') AS teams ORDER BY `group`");
$tables = "";
if($result){
while($data = mysql_fetch_assoc($result)){
$tables .= "<table><tr><td>" . str_replace("|","</td><td>", $data['teams']) . "</td></tr></table>";
}
}
echo $tables;
Try that. For future work avoid mysql_*, use mysqli_* or PDO.
diafol
Keep Smiling
10,654 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,510
Skill Endorsements: 57
Question Answered as of 3 Months Ago by
diafol
and
EvolutionFallen