Pivot
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
create table if not EXISTS trn_partijen(
id int PRIMARY KEY AUTO_INCREMENT,
id_toernooi int not null,
speler1 int not null,
speler2 int not null,
uitslag varchar(1) NOT NULL,
UNIQUE id_toernooi (id_toernooi,speler1,speler2)
);
id int PRIMARY KEY AUTO_INCREMENT,
id_toernooi int not null,
speler1 int not null,
speler2 int not null,
uitslag varchar(1) NOT NULL,
UNIQUE id_toernooi (id_toernooi,speler1,speler2)
);
Ik zou een draaitabel willen van speler1 naar speler2 met de uitslag als waarde, maar ik raak er niet uit.
Zoals je ziet is uitslag een varchar(1) met unieke index op speler1 en speler2
Ik zou dus voor 10 spelers 10 lijnen moeten krijgen met 11 kolommen
Dit is wat ik had maar ver van juist :)
Iemand een idee?
Jan
Gewijzigd op 15/03/2015 09:40:54 door Jan R
Welke tabellen heb je nu?
spelers en partijen stel ik me voor?
Gewijzigd op 15/03/2015 12:07:43 door Frank Nietbelangrijk
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SELECT
t.speler_naam thuis_naam,
t.speler_id thuis_id,
u.speler_naam uit_naam,
u.speler_id uit_id,
CASE WHEN t.speler_id = u.speler_id THEN 'X'
ELSE COALESCE(r.uitslag, '-') END uitslag
FROM
spelers t
CROSS JOIN
spelers u
LEFT JOIN
uitslagen r
ON t.speler_id = r.speler1 AND u.speler_id = r.speler2
ORDER BY thuis_id, uit_id
t.speler_naam thuis_naam,
t.speler_id thuis_id,
u.speler_naam uit_naam,
u.speler_id uit_id,
CASE WHEN t.speler_id = u.speler_id THEN 'X'
ELSE COALESCE(r.uitslag, '-') END uitslag
FROM
spelers t
CROSS JOIN
spelers u
LEFT JOIN
uitslagen r
ON t.speler_id = r.speler1 AND u.speler_id = r.speler2
ORDER BY thuis_id, uit_id
Met het resultaat uit deze querie kan je in PHP een draaitabel maken.
Nu 11 spelers ==> 100 querys
@Ger van Steenderen: Ik heb meerdere foutmeldingen in Uw oplossing. Er is ook geen uit of thuis. Het is gewoon iedereen tegen iedereen.
Voor 4 spelers = 6
Voor 10 spelers = 90
Om de ID's van de spelers om te zetten naar namen heb ik al een array uit en andere query.
Voor wie het nog niet doorhad :) het is voor het schaken.
Werkend voorbeeld maar dus met vééééééééééél querys: http://janr.be/toernooien/index.php?page=kruistabel
Eventueel eerst een toernooi kiezen in het 2° menu
Jan
Dit is toch wat je wilt?
Code (php)
1
2
3
4
5
6
2
3
4
5
6
-----------------------------------------
| speler 1 | speler 2 | speler 3
-----------------------------------------
speler 1 | | 3-4 | 3-4
speler 2 | 3-4 | | 3-4
speler 3 | 3-4 | 3-4 |
| speler 1 | speler 2 | speler 3
-----------------------------------------
speler 1 | | 3-4 | 3-4
speler 2 | 3-4 | | 3-4
speler 3 | 3-4 | 3-4 |
Toevoeging op 15/03/2015 23:29:30:
ok duidelijk
Toevoeging op 15/03/2015 23:30:19:
Welke tabellen heb je? spelers en partijen? welke kolommen staan er in?
Toevoeging op 16/03/2015 00:17:54:
here you go, met dank aan Ger:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
$query = "
SELECT
t.naam as naam,
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(r.score, '-') END as score
FROM
spelers t
CROSS JOIN
spelers u
LEFT JOIN
toernooi r
ON t.id = r.speler1 AND u.id = r.speler2
ORDER BY thuis_id, uit_id";
$con = mysqli_connect('localhost', 'frank', 'password', 'test');
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($result)) {
$list[$row['thuis_id']][] = $row;
}
//print_r($list);
echo '<table><tr><th> </th>';
foreach($list as $speler => $arr)
{
echo '<td>' . $arr[0]['naam'] . '</td>';
}
echo '</tr>';
foreach($list as $speler => $arr)
{
echo '<tr><td>' . $arr[0]['naam'] . '</td>';
foreach($arr as $cell)
{
echo '<td>' . $cell['score'] . '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
$query = "
SELECT
t.naam as naam,
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(r.score, '-') END as score
FROM
spelers t
CROSS JOIN
spelers u
LEFT JOIN
toernooi r
ON t.id = r.speler1 AND u.id = r.speler2
ORDER BY thuis_id, uit_id";
$con = mysqli_connect('localhost', 'frank', 'password', 'test');
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($result)) {
$list[$row['thuis_id']][] = $row;
}
//print_r($list);
echo '<table><tr><th> </th>';
foreach($list as $speler => $arr)
{
echo '<td>' . $arr[0]['naam'] . '</td>';
}
echo '</tr>';
foreach($list as $speler => $arr)
{
echo '<tr><td>' . $arr[0]['naam'] . '</td>';
foreach($arr as $cell)
{
echo '<td>' . $cell['score'] . '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
Gewijzigd op 16/03/2015 00:37:26 door Frank Nietbelangrijk
SELECT
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(t.uitslag, '-') END as score
FROM
trn_partijen t
CROSS JOIN
trn_partijen u
ORDER BY thuis_id, uit_id
Dit is echter niet mat ik wil/zoek.
Ook om alles via losse qry's te doen is niet echt efficient.
Stel ik heb 50 spelers 1 tegen allen dan worden dit ±2500 qry's :(
Ter herhaling. Ik heb slechts 1 tabel nodig waar ALLE info uit komt. Deze staat vermeld in het eerste bericht.
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
create table if not EXISTS trn_partijen(
id int PRIMARY KEY AUTO_INCREMENT,
id_toernooi int not null,
speler1 int not null,
speler2 int not null,
uitslag varchar(1) NOT NULL,
UNIQUE id_toernooi (id_toernooi,speler1,speler2)
);
id int PRIMARY KEY AUTO_INCREMENT,
id_toernooi int not null,
speler1 int not null,
speler2 int not null,
uitslag varchar(1) NOT NULL,
UNIQUE id_toernooi (id_toernooi,speler1,speler2)
);
ID_toernooi is het id van het toernooi. Een "where id_toernooi=s_SESSION['trn_id']" kan ik later gewoon toevoegen.
Speler1 en Speler2 zijn gewoon het id van de spelers wit en zwart welke ik via een array omzet naar een leesbare naam.
Uitslag= code voor de punten van Wit
1 verlies
2 remise
3 winst
0 verloren door forfait
F Gewonnen met forfait
U uitgesteld
A Afgebroken
? onbekend
Meer opties zijn er niet. Is er manueel toch iets anders ingevuld dan wordt dit ook onbekend. Dit moet via PHP blijven.
Geen combinatie = niet gespeeld.
Jan
Toevoeging op 16/03/2015 10:00:17:
Hier is de huidige tabel
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
CREATE TABLE trn_partijen (
id int(11) NOT NULL AUTO_INCREMENT,
id_toernooi int(11) NOT NULL,
speler1 int(11) NOT NULL,
speler2 int(11) NOT NULL,
uitslag varchar(1) COLLATE utf8_unicode_ci NOT NULL,
opmerking varchar(50) COLLATE utf8_unicode_ci DEFAULT '',
datum date DEFAULT NULL,
uitsteller int(11) DEFAULT '0',
PRIMARY KEY (id),
UNIQUE KEY id_toernooi (id_toernooi,speler1,speler2)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO trn_partijen VALUES("1","1","1","2","1","30-09-2014","2014-09-30","0");
INSERT INTO trn_partijen VALUES("2","1","1","3","1","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("3","1","1","4","1","14-10-2014","2014-10-14","0");
INSERT INTO trn_partijen VALUES("4","1","1","5","1","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("5","1","1","6","3","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("6","1","1","7","U","09-09-2014","2014-09-09","2");
INSERT INTO trn_partijen VALUES("7","1","1","8","1","25-11-2014","2014-11-25","0");
INSERT INTO trn_partijen VALUES("8","1","1","10","1","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("9","1","1","11","1","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("10","1","1","12","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("11","1","2","1","2","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("12","1","2","3","2","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("13","1","2","4","3","03-03-2015","2015-03-03","0");
INSERT INTO trn_partijen VALUES("14","1","2","5","3","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("15","1","2","6","U","07-10-2014","2014-10-07","2");
INSERT INTO trn_partijen VALUES("16","1","2","7","1","25-11-2014","2014-11-25","0");
INSERT INTO trn_partijen VALUES("17","1","2","11","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("18","1","2","12","1","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("19","1","3","1","3","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("20","1","3","2","U","03-02-2015","2015-02-03","3");
INSERT INTO trn_partijen VALUES("21","1","3","4","1","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("22","1","3","5","3","03-03-2015","2015-03-03","0");
INSERT INTO trn_partijen VALUES("23","1","3","6","U","25-11-2014","2014-11-25","1");
INSERT INTO trn_partijen VALUES("24","1","3","7","1","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("25","1","3","8","1","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("26","1","3","10","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("27","1","3","11","1","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("28","1","3","12","1","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("29","1","4","1","3","03-02-2015","2015-02-03","0");
INSERT INTO trn_partijen VALUES("30","1","4","2","3","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("31","1","4","3","3","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("32","1","4","5","3","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("33","1","4","7","1","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("34","1","4","8","2","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("35","1","4","10","2","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("36","1","4","11","1","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("37","1","4","12","2","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("38","1","5","1","3","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("39","1","5","2","3","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("40","1","5","3","1","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("41","1","5","4","1","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("42","1","5","6","3","09-12-2014","2014-12-09","0");
INSERT INTO trn_partijen VALUES("43","1","5","8","U","23-09-2014","2014-09-23","2");
INSERT INTO trn_partijen VALUES("44","1","5","10","U","07-10-2014","2014-10-07","1");
INSERT INTO trn_partijen VALUES("45","1","5","11","1","03-02-2015","2015-02-03","0");
INSERT INTO trn_partijen VALUES("46","1","5","12","3","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("47","1","6","1","2","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("48","1","6","2","2","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("49","1","6","3","U","07-10-2014","2014-10-07","1");
INSERT INTO trn_partijen VALUES("50","1","6","4","U","02-12-2014","2014-12-02","1");
INSERT INTO trn_partijen VALUES("51","1","6","7","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("52","1","6","8","2","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("53","1","6","10","1","03-02-2015","2015-02-03","1");
INSERT INTO trn_partijen VALUES("54","1","6","11","1","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("55","1","6","12","2","16-12-2014","2014-12-16","0");
INSERT INTO trn_partijen VALUES("56","1","7","1","3","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("57","1","7","3","3","09-12-2014","2014-12-09","0");
INSERT INTO trn_partijen VALUES("58","1","7","5","3","16-12-2014","2014-12-16","2");
INSERT INTO trn_partijen VALUES("59","1","7","6","3","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("60","1","7","8","3","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("61","1","7","10","3","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("62","1","7","11","3","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("63","1","7","12","3","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("64","1","8","1","2","03-03-2015","2015-03-03","0");
INSERT INTO trn_partijen VALUES("65","1","8","2","3","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("66","1","8","4","1","16-12-2014","2014-12-16","0");
INSERT INTO trn_partijen VALUES("67","1","8","5","2","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("68","1","8","6","3","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("69","1","8","7","U","27-01-2015","2015-01-27","1");
INSERT INTO trn_partijen VALUES("70","1","8","10","1","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("71","1","8","11","1","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("72","1","8","12","3","03-02-2015","2015-02-03","0");
INSERT INTO trn_partijen VALUES("73","1","10","2","3","16-12-2014","2014-12-16","0");
INSERT INTO trn_partijen VALUES("74","1","10","3","2","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("75","1","10","4","2","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("76","1","10","5","3","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("77","1","10","6","3","14-10-2014","2014-10-14","0");
INSERT INTO trn_partijen VALUES("78","1","10","7","1","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("79","1","10","8","3","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("80","1","10","11","3","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("81","1","10","12","2","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("82","1","11","1","3","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("83","1","11","2","2","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("84","1","11","3","3","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("85","1","11","4","3","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("86","1","11","5","1","14-10-2014","2014-10-14","0");
INSERT INTO trn_partijen VALUES("87","1","11","6","3","17-02-2015","2015-02-17","2");
INSERT INTO trn_partijen VALUES("88","1","11","7","1","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("89","1","11","8","U","03-03-2015","2015-03-03","1");
INSERT INTO trn_partijen VALUES("90","1","11","12","3","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("91","1","12","1","3","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("92","1","12","2","3","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("93","1","12","3","3","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("94","1","12","4","1","25-11-2014","2014-11-25","0");
INSERT INTO trn_partijen VALUES("95","1","12","7","1","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("96","1","12","8","2","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("97","1","12","10","1","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("98","1","12","11","1","09-12-2014","2014-12-09","0");
id int(11) NOT NULL AUTO_INCREMENT,
id_toernooi int(11) NOT NULL,
speler1 int(11) NOT NULL,
speler2 int(11) NOT NULL,
uitslag varchar(1) COLLATE utf8_unicode_ci NOT NULL,
opmerking varchar(50) COLLATE utf8_unicode_ci DEFAULT '',
datum date DEFAULT NULL,
uitsteller int(11) DEFAULT '0',
PRIMARY KEY (id),
UNIQUE KEY id_toernooi (id_toernooi,speler1,speler2)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO trn_partijen VALUES("1","1","1","2","1","30-09-2014","2014-09-30","0");
INSERT INTO trn_partijen VALUES("2","1","1","3","1","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("3","1","1","4","1","14-10-2014","2014-10-14","0");
INSERT INTO trn_partijen VALUES("4","1","1","5","1","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("5","1","1","6","3","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("6","1","1","7","U","09-09-2014","2014-09-09","2");
INSERT INTO trn_partijen VALUES("7","1","1","8","1","25-11-2014","2014-11-25","0");
INSERT INTO trn_partijen VALUES("8","1","1","10","1","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("9","1","1","11","1","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("10","1","1","12","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("11","1","2","1","2","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("12","1","2","3","2","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("13","1","2","4","3","03-03-2015","2015-03-03","0");
INSERT INTO trn_partijen VALUES("14","1","2","5","3","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("15","1","2","6","U","07-10-2014","2014-10-07","2");
INSERT INTO trn_partijen VALUES("16","1","2","7","1","25-11-2014","2014-11-25","0");
INSERT INTO trn_partijen VALUES("17","1","2","11","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("18","1","2","12","1","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("19","1","3","1","3","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("20","1","3","2","U","03-02-2015","2015-02-03","3");
INSERT INTO trn_partijen VALUES("21","1","3","4","1","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("22","1","3","5","3","03-03-2015","2015-03-03","0");
INSERT INTO trn_partijen VALUES("23","1","3","6","U","25-11-2014","2014-11-25","1");
INSERT INTO trn_partijen VALUES("24","1","3","7","1","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("25","1","3","8","1","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("26","1","3","10","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("27","1","3","11","1","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("28","1","3","12","1","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("29","1","4","1","3","03-02-2015","2015-02-03","0");
INSERT INTO trn_partijen VALUES("30","1","4","2","3","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("31","1","4","3","3","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("32","1","4","5","3","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("33","1","4","7","1","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("34","1","4","8","2","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("35","1","4","10","2","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("36","1","4","11","1","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("37","1","4","12","2","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("38","1","5","1","3","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("39","1","5","2","3","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("40","1","5","3","1","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("41","1","5","4","1","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("42","1","5","6","3","09-12-2014","2014-12-09","0");
INSERT INTO trn_partijen VALUES("43","1","5","8","U","23-09-2014","2014-09-23","2");
INSERT INTO trn_partijen VALUES("44","1","5","10","U","07-10-2014","2014-10-07","1");
INSERT INTO trn_partijen VALUES("45","1","5","11","1","03-02-2015","2015-02-03","0");
INSERT INTO trn_partijen VALUES("46","1","5","12","3","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("47","1","6","1","2","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("48","1","6","2","2","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("49","1","6","3","U","07-10-2014","2014-10-07","1");
INSERT INTO trn_partijen VALUES("50","1","6","4","U","02-12-2014","2014-12-02","1");
INSERT INTO trn_partijen VALUES("51","1","6","7","1","23-09-2014","2014-09-23","0");
INSERT INTO trn_partijen VALUES("52","1","6","8","2","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("53","1","6","10","1","03-02-2015","2015-02-03","1");
INSERT INTO trn_partijen VALUES("54","1","6","11","1","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("55","1","6","12","2","16-12-2014","2014-12-16","0");
INSERT INTO trn_partijen VALUES("56","1","7","1","3","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("57","1","7","3","3","09-12-2014","2014-12-09","0");
INSERT INTO trn_partijen VALUES("58","1","7","5","3","16-12-2014","2014-12-16","2");
INSERT INTO trn_partijen VALUES("59","1","7","6","3","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("60","1","7","8","3","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("61","1","7","10","3","21-10-2014","2014-10-21","0");
INSERT INTO trn_partijen VALUES("62","1","7","11","3","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("63","1","7","12","3","","0001-01-01","0");
INSERT INTO trn_partijen VALUES("64","1","8","1","2","03-03-2015","2015-03-03","0");
INSERT INTO trn_partijen VALUES("65","1","8","2","3","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("66","1","8","4","1","16-12-2014","2014-12-16","0");
INSERT INTO trn_partijen VALUES("67","1","8","5","2","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("68","1","8","6","3","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("69","1","8","7","U","27-01-2015","2015-01-27","1");
INSERT INTO trn_partijen VALUES("70","1","8","10","1","24-02-2015","2015-02-24","0");
INSERT INTO trn_partijen VALUES("71","1","8","11","1","04-11-2014","2014-11-04","0");
INSERT INTO trn_partijen VALUES("72","1","8","12","3","03-02-2015","2015-02-03","0");
INSERT INTO trn_partijen VALUES("73","1","10","2","3","16-12-2014","2014-12-16","0");
INSERT INTO trn_partijen VALUES("74","1","10","3","2","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("75","1","10","4","2","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("76","1","10","5","3","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("77","1","10","6","3","14-10-2014","2014-10-14","0");
INSERT INTO trn_partijen VALUES("78","1","10","7","1","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("79","1","10","8","3","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("80","1","10","11","3","02-12-2014","2014-12-02","0");
INSERT INTO trn_partijen VALUES("81","1","10","12","2","10-03-2015","2015-03-10","0");
INSERT INTO trn_partijen VALUES("82","1","11","1","3","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("83","1","11","2","2","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("84","1","11","3","3","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("85","1","11","4","3","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("86","1","11","5","1","14-10-2014","2014-10-14","0");
INSERT INTO trn_partijen VALUES("87","1","11","6","3","17-02-2015","2015-02-17","2");
INSERT INTO trn_partijen VALUES("88","1","11","7","1","28-10-2014","2014-10-28","0");
INSERT INTO trn_partijen VALUES("89","1","11","8","U","03-03-2015","2015-03-03","1");
INSERT INTO trn_partijen VALUES("90","1","11","12","3","23-12-2014","2014-12-23","0");
INSERT INTO trn_partijen VALUES("91","1","12","1","3","13-01-2015","2015-01-13","0");
INSERT INTO trn_partijen VALUES("92","1","12","2","3","27-01-2015","2015-01-27","0");
INSERT INTO trn_partijen VALUES("93","1","12","3","3","17-02-2015","2015-02-17","0");
INSERT INTO trn_partijen VALUES("94","1","12","4","1","25-11-2014","2014-11-25","0");
INSERT INTO trn_partijen VALUES("95","1","12","7","1","07-10-2014","2014-10-07","0");
INSERT INTO trn_partijen VALUES("96","1","12","8","2","18-11-2014","2014-11-18","0");
INSERT INTO trn_partijen VALUES("97","1","12","10","1","10-02-2015","2015-02-10","0");
INSERT INTO trn_partijen VALUES("98","1","12","11","1","09-12-2014","2014-12-09","0");
Gewijzigd op 16/03/2015 10:04:16 door Jan R
Het probleem dat je dan krijgt is dat als je halverwege een toernooi bent -en nog niet alle spelers 1 partij hebben gespeeld- nog niet alle speler id's of in jouw tabel staan. Derhalve is het ook -denk ik- niet mogelijk om op een eenvoudige manier een tabel te creëren waarin dan wel alle spelers voorkomen die aan het toernooi meedoen. Met andere woorden moet ergens een volledige lijst van de deelnemers gehaald worden om jouw tabel te kunnen maken.
Wat ik een beetje vreemd vind is dat je het aantal queries laag wil houden (liefst alle data in één keer ophalen wat nodig is voor de tabel) maar dat je dan wel met array's wilt gaan klooien om er weer de namen van de spelers aan te koppelen. Ik zou dat niet doen. Ik zou de namen en indien nodig ook de id's van de spelers er bij gebruiken.
Als je in een eerder stadium al gegevens van spelers ophaalt gebruik je al meerdere tabellen, alleen leg je de relatie via PHP (zoals Frank al aangeeft).
Als je maar één tabel hebt ben database technisch gezien niet goed bezig, want de partijen bepalen niet de deelnemers maar de deelnemers bepalen de partijen die er gespeeld moeten worden.
Omdat ik niet weet welke tabellen je precies hebt, is mijn voorbeeld wat in het algemeen. Ik zelf heb dus een tabel waar per toernooi/competitie de deelnemers in vastgelegd zijn, en als je vanuit die tabel selecteert kan je alle mogelijke combinaties aan elkaar koppelen.
Als je de deelnemers per toernooi moet je de CROSS JOIN in een 'normale' JOIN veranderen:
Code (php)
1
2
3
4
2
3
4
.....
FROM toernooi_deelnemers w
JOIN toernooi_deelnemers z
ON w.toernooi_id = 1234 AND w.toernooi_id = z.toernooi_id
FROM toernooi_deelnemers w
JOIN toernooi_deelnemers z
ON w.toernooi_id = 1234 AND w.toernooi_id = z.toernooi_id
Bijkomend voordeel hiervan is dat je een deelnemer ook aan zich zelf kan koppelen, en zodoende een éénduidige sortering krijgt.
Maar gezien deze al ingeladen waren in een array voor berekening van de punten zag ik hier geen meerwaarde. Bedankt voor de uitleg.
De tabellen
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
CREATE TABLE trn_spelers (
id int(11) NOT NULL AUTO_INCREMENT,
id_toernooi int(11) NOT NULL,
naam varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
voorsprong_punten float DEFAULT '0',
voorsprong_weerstandspunten float DEFAULT '0',
voorsprong_winstpunten float DEFAULT '0',
stamnummer varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
elo varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
opmerking varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY id_toernooi (id_toernooi,naam)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE trn_toernooien (
id int(11) NOT NULL AUTO_INCREMENT,
naam varchar(50) COLLATE utf8_unicode_ci NOT NULL,
groep int(11) NOT NULL,
omschrijving varchar(50) COLLATE utf8_unicode_ci DEFAULT '',
ronden int(11) NOT NULL DEFAULT '2',
p_winst float NOT NULL DEFAULT '3',
p_remise float NOT NULL DEFAULT '2',
p_verlies float NOT NULL DEFAULT '1',
p_geefforfait float NOT NULL DEFAULT '0',
p_krijgforfait float NOT NULL DEFAULT '3',
p_afgebroken float NOT NULL DEFAULT '0',
p_uitgesteld float NOT NULL DEFAULT '0',
p_onbekend float DEFAULT '0',
s_winst varchar(1) COLLATE utf8_unicode_ci DEFAULT '3',
s_remise varchar(1) COLLATE utf8_unicode_ci DEFAULT '2',
s_verlies varchar(1) COLLATE utf8_unicode_ci DEFAULT '1',
s_geefforfait varchar(1) COLLATE utf8_unicode_ci DEFAULT '0',
s_krijgforfait varchar(1) COLLATE utf8_unicode_ci DEFAULT 'F',
s_afgebroken varchar(1) COLLATE utf8_unicode_ci DEFAULT 'A',
s_uitgesteld varchar(1) COLLATE utf8_unicode_ci DEFAULT 'U',
s_onbekend varchar(1) COLLATE utf8_unicode_ci DEFAULT '?',
PRIMARY KEY (id),
UNIQUE KEY naam (naam)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
id int(11) NOT NULL AUTO_INCREMENT,
id_toernooi int(11) NOT NULL,
naam varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
voorsprong_punten float DEFAULT '0',
voorsprong_weerstandspunten float DEFAULT '0',
voorsprong_winstpunten float DEFAULT '0',
stamnummer varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
elo varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
opmerking varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE KEY id_toernooi (id_toernooi,naam)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE trn_toernooien (
id int(11) NOT NULL AUTO_INCREMENT,
naam varchar(50) COLLATE utf8_unicode_ci NOT NULL,
groep int(11) NOT NULL,
omschrijving varchar(50) COLLATE utf8_unicode_ci DEFAULT '',
ronden int(11) NOT NULL DEFAULT '2',
p_winst float NOT NULL DEFAULT '3',
p_remise float NOT NULL DEFAULT '2',
p_verlies float NOT NULL DEFAULT '1',
p_geefforfait float NOT NULL DEFAULT '0',
p_krijgforfait float NOT NULL DEFAULT '3',
p_afgebroken float NOT NULL DEFAULT '0',
p_uitgesteld float NOT NULL DEFAULT '0',
p_onbekend float DEFAULT '0',
s_winst varchar(1) COLLATE utf8_unicode_ci DEFAULT '3',
s_remise varchar(1) COLLATE utf8_unicode_ci DEFAULT '2',
s_verlies varchar(1) COLLATE utf8_unicode_ci DEFAULT '1',
s_geefforfait varchar(1) COLLATE utf8_unicode_ci DEFAULT '0',
s_krijgforfait varchar(1) COLLATE utf8_unicode_ci DEFAULT 'F',
s_afgebroken varchar(1) COLLATE utf8_unicode_ci DEFAULT 'A',
s_uitgesteld varchar(1) COLLATE utf8_unicode_ci DEFAULT 'U',
s_onbekend varchar(1) COLLATE utf8_unicode_ci DEFAULT '?',
PRIMARY KEY (id),
UNIQUE KEY naam (naam)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
hun inhoud
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Insert into trn_toernooien (naam,omschrijving) values ('New exported tournament','Geexporteerd op 11/03/2015');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 01',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 02',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 03',0, 0, 0, 41556, '1388', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 04',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 05',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 06',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 07',0, 0, 0, 8397, '1843', 'Clubkampioen 2013-2014 / Simultaan 4+, 5=');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 08',0, 0, 0, 32557, '1288', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 09',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 10',0, 0, 0, 13718, '', 'Postkampioen 2013-2014');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 11',0, 0, 0, 32409, ' 1577', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 12',0, 0, 0, 7277, '1443', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 01',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 02',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 03',0, 0, 0, 41556, '1388', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 04',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 05',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 06',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 07',0, 0, 0, 8397, '1843', 'Clubkampioen 2013-2014 / Simultaan 4+, 5=');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 08',0, 0, 0, 32557, '1288', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 09',0, 0, 0, 0, '', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 10',0, 0, 0, 13718, '', 'Postkampioen 2013-2014');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 11',0, 0, 0, 32409, ' 1577', '');
insert into trn_spelers(id_toernooi, naam, voorsprong_punten, voorsprong_weerstandspunten, voorsprong_winstpunten, stamnummer, elo, opmerking) values ((SELECT max(id) FROM trn_toernooien),'Speler 12',0, 0, 0, 7277, '1443', '');
Het invoeren van de namen en partijen gelink aan de naam lijkt misschien raar maar deze komen vanuit een Windows programma welke ik daarna via PHPMyadmin inlaad
Jan
De totale set met tabellen http://www.janr.be/toernooien/maaktabellen.txt
Toevoeging op 16/03/2015 15:55:07:
Dit bestand blijft natuurlijk op de server staan als alles werkt :)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
$toernooi = 2;
$query = "
SELECT
t.naam as naam,
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(r.uitslag, '-') END as score
FROM
trn_spelers t
CROSS JOIN
trn_spelers u
LEFT JOIN
trn_partijen r
ON t.id = r.speler1
AND u.id = r.speler2
AND r.id_toernooi=t.id_toernooi
AND r.id_toernooi=u.id_toernooi
AND r.id_toernooi=" . $toernooi . "
ORDER BY thuis_id, uit_id";
$con = mysqli_connect('localhost', 'frank', 'password', 'test');
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($result)) {
$list[$row['thuis_id']]['naam'] = $row['naam'];
$list[$row['thuis_id']][] = $row['score'];
}
//print_r($list);
echo '<table><tr><th> </th>';
foreach($list as $speler => $arr)
{
echo '<td>' . $arr['naam'] . '</td>';
}
echo '</tr>';
foreach($list as $arr)
{
foreach($arr as $cell)
{
echo '<td>' . $cell . '</td>';
}
echo '</tr>';
}
echo '</table>';
[/code]
$toernooi = 2;
$query = "
SELECT
t.naam as naam,
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(r.uitslag, '-') END as score
FROM
trn_spelers t
CROSS JOIN
trn_spelers u
LEFT JOIN
trn_partijen r
ON t.id = r.speler1
AND u.id = r.speler2
AND r.id_toernooi=t.id_toernooi
AND r.id_toernooi=u.id_toernooi
AND r.id_toernooi=" . $toernooi . "
ORDER BY thuis_id, uit_id";
$con = mysqli_connect('localhost', 'frank', 'password', 'test');
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($result)) {
$list[$row['thuis_id']]['naam'] = $row['naam'];
$list[$row['thuis_id']][] = $row['score'];
}
//print_r($list);
echo '<table><tr><th> </th>';
foreach($list as $speler => $arr)
{
echo '<td>' . $arr['naam'] . '</td>';
}
echo '</tr>';
foreach($list as $arr)
{
foreach($arr as $cell)
{
echo '<td>' . $cell . '</td>';
}
echo '</tr>';
}
echo '</table>';
[/code]
Gewijzigd op 16/03/2015 17:50:56 door Frank Nietbelangrijk
Ik dank U hartelijk.
De 2 loops zijn eigelijk de hulp.
Jan
Fijn dat je het werkend hebt Jan.
Nu nog wat extra berekeningen maar de basis is er. De punten moeten nog uitgerekend worden op sommige niveaus maar ook daar is de basis al.
Nogmaals beiden bedankt.
Jan
Gewijzigd op 16/03/2015 22:27:59 door Ger van Steenderen
Ik heb mijn code voor een andere pagina gekopieerd en de where uitgebreid.
Als ik verwijs in de where naar uitslag. de originele naam van het veld dan heb ik niet alle ONGESPEELDE partijen. Als ik probeer met score. de nieuwe gecombineerde naam dan krijg ik de melding dat dit veld niet bestaat. nogtans als ik de query uitvoer via dbadmin zie ik een veld score. ik heb ook geprobeerd met te verwijzen naar de tabel t. u. of r. er voor.
U staat voor uitgesteld, A voor afgebroken ?, voor onbekend en . komt uit de query(partij nog niet ingegeven).
Wat doe ik mis?
Jan
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
$query = "
SELECT
t.naam as naam,
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(r.uitslag, '.') END as score,
u.naam as tegenstander
FROM
trn_spelers t
CROSS JOIN
trn_spelers u
LEFT JOIN
trn_partijen r
ON t.id = r.speler1
AND u.id = r.speler2
AND r.id_toernooi=t.id_toernooi
AND r.id_toernooi=u.id_toernooi
AND r.id_toernooi=" . $toernooi . "
where t.id_toernooi=". $toernooi . " and u.id_toernooi = ". $toernooi . " and uitslag in ('U', 'A', '.', '?')
ORDER BY thuis_id, uit_id
";
$spelers=GetPlayers($con);
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($result)) {
if (!(fIsPlayerABye($row['naam'])) && !(fIsPlayerABye($row['tegenstander']))){
echo '<div class="partij"><span>' . $row['naam'] .'</span>';
echo ' - ';
echo '<span>' . $row['tegenstander'] .'</span></div>' . PHP_EOL;
}
}
?>
$query = "
SELECT
t.naam as naam,
t.id as thuis_id,
u.id as uit_id,
CASE WHEN t.id = u.id THEN 'X'
ELSE COALESCE(r.uitslag, '.') END as score,
u.naam as tegenstander
FROM
trn_spelers t
CROSS JOIN
trn_spelers u
LEFT JOIN
trn_partijen r
ON t.id = r.speler1
AND u.id = r.speler2
AND r.id_toernooi=t.id_toernooi
AND r.id_toernooi=u.id_toernooi
AND r.id_toernooi=" . $toernooi . "
where t.id_toernooi=". $toernooi . " and u.id_toernooi = ". $toernooi . " and uitslag in ('U', 'A', '.', '?')
ORDER BY thuis_id, uit_id
";
$spelers=GetPlayers($con);
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_assoc($result)) {
if (!(fIsPlayerABye($row['naam'])) && !(fIsPlayerABye($row['tegenstander']))){
echo '<div class="partij"><span>' . $row['naam'] .'</span>';
echo ' - ';
echo '<span>' . $row['tegenstander'] .'</span></div>' . PHP_EOL;
}
}
?>
Je kan wel r.uitslag IS NULL gebruiken.
Jan