Réponse 12 Ligne 36
Version imprimable
Réponse 12 Ligne 36
Modifié en ligne 36.Code:$answers[$v['inscription_id']] = array_fill_keys($ids_question, ' ');
Messages d'erreurs:
Pièce jointe 310889
Toujours pas de bon fonctionnement.
Avec les codes affichant ces résultats j'y était presque arrivé:
Pièce jointe 310893
Sauf que lorsqu' un membre ne répondait pas à une question la cellule au lieu d'être vide, celle ci était remplie par la question suivante.
Code mis à jour :
Code:
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 <?php include 'connexion.php'; // code html tableau $html_header_question = ''; $html_header_coef = ''; $html_body = ''; $ids_question = []; // création du code html de l'en-tête foreach ($connection->query('SELECT id, coef FROM coeffi ORDER BY id', PDO::FETCH_ASSOC) as $v) { $html_header_question .= '<th>'.(int)$v['id'].'</th>'; $html_header_coef .= '<th>'.(int)$v['coef'].'</th>'; $ids_question[] = (int)$v['id']; } // fonction d'échappement des caractères dangereux $hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); }; // résultats du questionnaire $sql = <<<'sql' SELECT username, inscription_id, titre_id, point_total FROM reponses r INNER JOIN inscriptions i ON i.id = r.inscription_id INNER JOIN coeffi c ON c.id = r.titre_id ORDER BY username, titre_id sql; $last_user_id = ''; $answers = []; // vu qu'il n'y a aucun paramèrtre, la préparation de la requête est inutile foreach ($connection->query($sql, PDO::FETCH_ASSOC) as $v) { // gestion des nouveaux noms if ($last_user_id !== (int)$v['inscription_id']) { $answers[$v['inscription_id']] = array_fill_keys($ids_question, ' '); $answers[$v['inscription_id']]['username'] = $v['username']; $last_user_id = $v['inscription_id']; } $answers[$last_user_id][(int)$v['titre_id']] = (int)$v['point_total']; } foreach ($answers as $user_id => $v) { $html_body .= '<tr><td>'.$hsc(array_pop($v)).'</td>'; // username $html_body .= '<td>'.implode('</td><td>', $v).'</td></tr>'; } ?> <!DOCTYPE html> <html> <head> <title>Résultats</title> <meta charset="utf-8" /><!--Pour obtenir les bons caractères--> </head> <body> <table> <thead> <tr><th>Question n°</th><?= $html_header_question ?></tr> <tr><th>Coefficient</th><?= $html_header_coef ?></tr> </thead> <tbody> <?= $html_body ?> </tbody> </table> </body> </html>
Quelle syntax exacte en ligne 12?
Message d'erreur suivant après reprise de toutes les lignes que vous m'indiquez:
Pièce jointe 310894
Allez reprend le code et refait un essai, cela devrait être bon.
Je n'avais pas mis le tiret dans utf-8
Voulez vous recevoir mes tables par messages privés pour que vous puissiez faire les essais directement?
Pas besoin, reprend le code du message 23 et réessaie stp
Il manque des données concernant les points de chaque utilisateur.
Après pour la mise en colonne je m'en charge.
Mais avant il faut régler ce dernier problème auquel je me sent incapable de résoudre en ce moment.
Pièce jointe 310895
Quel est plus exactement le message du 23?
ok j'ai localisé le 23
ok. Repris les codes du message 23.
Mais même résultat qu'au message 29.
Exemple pour Pierre:
Il a répondu à la question une et obtenu 1 points.
Ainsi qu' à la question 3 et obtenu 2 points.
Il n'a pas répondu à la question 2 et par conséquent l'emplacement de cette question ne devrait pas comporter de chiffre en attendant plus tard qu'il répond.
En ligne 38 mets :
en ligne 42 :Code:$last_user_id = (int)$v['inscription_id'];
Poste ici le résultat stpCode:var_dump($answers);
Enfin exécute le code, fais CTRL+U sur la page et poste le code stp
array (size=4)
4 =>
array (size=16)
1 => int 1
2 => int 2
3 => int 2
4 => string ' ' (length=6)
5 => string ' ' (length=6)
6 => string ' ' (length=6)
7 => string ' ' (length=6)
8 => string ' ' (length=6)
9 => string ' ' (length=6)
10 => string ' ' (length=6)
11 => string ' ' (length=6)
12 => string ' ' (length=6)
13 => string ' ' (length=6)
14 => string ' ' (length=6)
15 => string ' ' (length=6)
'username' => string 'Jacques' (length=7)
1 =>
array (size=16)
1 => int 1
2 => string ' ' (length=6)
3 => string ' ' (length=6)
4 => string ' ' (length=6)
5 => string ' ' (length=6)
6 => string ' ' (length=6)
7 => string ' ' (length=6)
8 => string ' ' (length=6)
9 => string ' ' (length=6)
10 => string ' ' (length=6)
11 => string ' ' (length=6)
12 => string ' ' (length=6)
13 => string ' ' (length=6)
14 => string ' ' (length=6)
15 => string ' ' (length=6)
'username' => string 'Jean' (length=4)
3 =>
array (size=16)
1 => int 1
2 => int 2
3 => string ' ' (length=6)
4 => string ' ' (length=6)
5 => string ' ' (length=6)
6 => string ' ' (length=6)
7 => string ' ' (length=6)
8 => string ' ' (length=6)
9 => string ' ' (length=6)
10 => string ' ' (length=6)
11 => string ' ' (length=6)
12 => string ' ' (length=6)
13 => string ' ' (length=6)
14 => string ' ' (length=6)
15 => string ' ' (length=6)
'username' => string 'Paul' (length=4)
2 =>
array (size=16)
1 => int 1
2 => string ' ' (length=6)
3 => int 2
4 => string ' ' (length=6)
5 => string ' ' (length=6)
6 => string ' ' (length=6)
7 => string ' ' (length=6)
8 => string ' ' (length=6)
9 => string ' ' (length=6)
10 => string ' ' (length=6)
11 => string ' ' (length=6)
12 => string ' ' (length=6)
13 => string ' ' (length=6)
14 => string ' ' (length=6)
15 => string ' ' (length=6)
'username' => string 'Pierre' (length=6)
Question n° 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Coefficient 1 2 2 2 1 1 2 1 2 1 2 1 2 1 2
Jacques 1 2 2
Jean 1
Paul 1 2
Pierre 1 2
Concernant Pierre, il devrait y avoir une séparation entre sa réponse 1 et sa réponse 3.
Bon ça me semble nickel,
il faut juste que dans le navigateur tu fasses CTRL+U sur ta page de résultats et que tu rapatries le code source ici.
La séparation tu l'as sauf que tu ne la vois pas d'où la raison de ma demande du code source HTML
Non ok c'est correct.
Sur ma page internet il y a bien la séparation entre les deux réponses de Pierre.
Excusez moi.
Pour le plaisir :
Pièce jointe 310909
:)
Tiens essaie voir avec un peu de css :
Code:
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 <!DOCTYPE html> <html> <head> <title>Résultats</title> <meta charset="utf-8" /><!--Pour obtenir les bons caractères--> <style type="text/css"> table { font-family: Helvetica, Arial, sans-serif; border-collapse: collapse; border-spacing: 0; } td, th { border: 1px solid #CCC; height: 30px; } th { background: #F3F3F3; font-weight: bold; } td { background: #FAFAFA; text-align: center; } </style> </head> <body> <table> <thead> <tr><th>Question n°</th><?= $html_header_question ?></tr> <tr><th>Coefficient</th><?= $html_header_coef ?></tr> </thead> <tbody> <?= $html_body ?> </tbody> </table> </body> </html>