IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

foreach imbriqués pour récupération de données [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut foreach imbriqués pour récupération de données
    Bonjour,

    Je souhaite faire des foreach imbriqués sur un résultat de requêtes mySQL.

    Je récupère dans un premier 'foreach' les résultats de ma requête 1, ensuite je voudrais un second 'foreach' qui me récupère les valeurs pour chaque valeurs trouvées dans le premier foreach et mettre 0 comme valeur si rien trouvé...

    En gros:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    foreach($NumNccUnique as $NumNccUnique){
    		echo "name: '".$NumNccUnique['ErrorNumber']."',".'<br>';
     
    			foreach(POUR CHAQUE VALEURS $NumNccUnique['ErrorNumber'] JE RECUPERE LES VALEURS ASSOCIEES){
    				echo 'ici les valeurs';
    	}
    	echo "]";
    	echo '<br>';
     
     
    }
    Merci par avance

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    fais un var_dump($NumNccUnique), et tu sauras ce qu'il contient et comment le traiter.

  3. #3
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $NumNccUnique as $NumNccUnique
    C'est normal que tu aies mis deux fois la même variable?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  4. #4
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    Heu non, c'est une erreur de ma part...

    Oui le var_dump j'ai déjà fait...

    En fait, je me suis mal exprimé, j'ai cogité ce week-end...

    Voici le résultat de ma requête:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
     
    Line,CSL,Semaine,QtyByNCCcode,CodeNCC
    SUV_1,"Xr3_Vz",1,1,1
    SUV_1,"Xr3_Vz",1,3,101
    SUV_1,"Xr3_Vz",1,4,102
    SUV_1,"Xr3_Vz",1,27,104
    SUV_1,"Xr3_Vz",1,53,105
    SUV_1,"Xr3_Vz",1,18,106
    SUV_1,"Xr3_Vz",1,1,107
    SUV_1,"Xr3_Vz",1,1,999
    SUV_1,"Xr3_Vz",2,2,101
    SUV_1,"Xr3_Vz",2,4,102
    SUV_1,"Xr3_Vz",2,30,104
    SUV_1,"Xr3_Vz",2,20,105
    SUV_1,"Xr3_Vz",2,8,106
    SUV_1,"Xr3_Vz",2,1,109
    SUV_1,"Xr3_Vz",2,3,113
    SUV_1,"Xr3_Vz",2,1,3
    SUV_1,"Xr3_Vz",2,8,999
    SUV_1,"Xr3_Vz",3,7,101
    SUV_1,"Xr3_Vz",3,1,102
    SUV_1,"Xr3_Vz",3,13,104
    SUV_1,"Xr3_Vz",3,21,105
    SUV_1,"Xr3_Vz",3,9,106
    SUV_1,"Xr3_Vz",3,1,999
    SUV_1,"Xr3_Vz",4,14,101
    SUV_1,"Xr3_Vz",4,12,104
    SUV_1,"Xr3_Vz",4,12,105
    SUV_1,"Xr3_Vz",4,3,106
    SUV_1,"Xr3_Vz",4,2,110
    SUV_1,"Xr3_Vz",4,4,113
    SUV_1,"Xr3_Vz",4,1,999
    SUV_1,"Xr3_Vz",5,5,101
    SUV_1,"Xr3_Vz",5,3,104
    SUV_1,"Xr3_Vz",5,7,105
    SUV_1,"Xr3_Vz",5,5,106
    SUV_1,"Xr3_Vz",5,2,110
    SUV_1,"Xr3_Vz",6,2,101
    SUV_1,"Xr3_Vz",6,4,102
    SUV_1,"Xr3_Vz",6,2,103
    SUV_1,"Xr3_Vz",6,4,104
    SUV_1,"Xr3_Vz",6,5,105
    SUV_1,"Xr3_Vz",6,4,106
    SUV_1,"Xr3_Vz",6,1,110
    SUV_1,"Xr3_Vz",7,1,1
    SUV_1,"Xr3_Vz",7,5,101
    SUV_1,"Xr3_Vz",7,1,102
    SUV_1,"Xr3_Vz",7,4,104
    SUV_1,"Xr3_Vz",7,21,105
    SUV_1,"Xr3_Vz",7,6,106
    SUV_1,"Xr3_Vz",7,2,110
    SUV_1,"Xr3_Vz",7,1,112
    SUV_1,"Xr3_Vz",7,1,113
    SUV_1,"Xr3_Vz",8,1,101
    SUV_1,"Xr3_Vz",8,4,102
    SUV_1,"Xr3_Vz",8,1,103
    SUV_1,"Xr3_Vz",8,19,104
    SUV_1,"Xr3_Vz",8,9,105
    SUV_1,"Xr3_Vz",8,11,106
    SUV_1,"Xr3_Vz",8,1,109
    SUV_1,"Xr3_Vz",8,1,110
    SUV_1,"Xr3_Vz",8,5,113
    SUV_1,"Xr3_Vz",9,2,101
    SUV_1,"Xr3_Vz",9,2,102
    SUV_1,"Xr3_Vz",9,1,103
    SUV_1,"Xr3_Vz",9,45,104
    SUV_1,"Xr3_Vz",9,10,105
    SUV_1,"Xr3_Vz",9,2,106
    SUV_1,"Xr3_Vz",9,1,109
    SUV_1,"Xr3_Vz",9,2,110
    SUV_1,"Xr3_Vz",9,2,113
    SUV_1,"Xr3_Vz",9,2,999
    SUV_1,"Xr3_Vz",10,4,104
    SUV_1,"Xr3_Vz",10,6,105
    SUV_1,"Xr3_Vz",10,5,106
    SUV_1,"Xr3_Vz",10,3,113
    SUV_1,"Xr3_Vz",11,1,101
    SUV_1,"Xr3_Vz",11,1,102
    SUV_1,"Xr3_Vz",11,6,104
    SUV_1,"Xr3_Vz",11,22,105
    SUV_1,"Xr3_Vz",11,10,106
    SUV_1,"Xr3_Vz",11,1,109
    SUV_1,"Xr3_Vz",11,1,110
    SUV_1,"Xr3_Vz",11,1,112
    SUV_1,"Xr3_Vz",11,8,113
    SUV_1,"Xr3_Vz",11,4,999
    SUV_1,"Xr3_Vz",12,7,101
    SUV_1,"Xr3_Vz",12,3,102
    SUV_1,"Xr3_Vz",12,1,103
    SUV_1,"Xr3_Vz",12,8,104
    SUV_1,"Xr3_Vz",12,20,105
    SUV_1,"Xr3_Vz",12,4,106
    SUV_1,"Xr3_Vz",12,5,113
    SUV_1,"Xr3_Vz",12,1,999
    SUV_1,"Xr3_Vz",13,2,102
    SUV_1,"Xr3_Vz",13,16,104
    SUV_1,"Xr3_Vz",13,33,105
    SUV_1,"Xr3_Vz",13,1,106
    SUV_1,"Xr3_Vz",13,2,107
    SUV_1,"Xr3_Vz",13,2,109
    SUV_1,"Xr3_Vz",13,1,112
    SUV_1,"Xr3_Vz",13,7,113
    SUV_1,"Xr3_Vz",13,1,999
    SUV_1,"Xr3_Vz",14,4,101
    SUV_1,"Xr3_Vz",14,3,102
    SUV_1,"Xr3_Vz",14,1,103
    SUV_1,"Xr3_Vz",14,3,104
    SUV_1,"Xr3_Vz",14,92,105
    SUV_1,"Xr3_Vz",14,20,106
    SUV_1,"Xr3_Vz",14,1,109
    SUV_1,"Xr3_Vz",14,2,113
    SUV_1,"Xr3_Vz",14,2,3
    SUV_1,"Xr3_Vz",14,1,999
    SUV_1,"Xr3_Vz",15,3,102
    SUV_1,"Xr3_Vz",15,52,104
    SUV_1,"Xr3_Vz",15,48,105
    SUV_1,"Xr3_Vz",15,1,106
    SUV_1,"Xr3_Vz",15,6,113
    SUV_1,"Xr3_Vz",16,2,101
    SUV_1,"Xr3_Vz",16,2,102
    SUV_1,"Xr3_Vz",16,6,104
    SUV_1,"Xr3_Vz",16,70,105
    SUV_1,"Xr3_Vz",16,28,106
    SUV_1,"Xr3_Vz",16,6,113
    SUV_1,"Xr3_Vz",16,2,999
    SUV_1,"Xr3_Vz",17,2,101
    SUV_1,"Xr3_Vz",17,3,102
    SUV_1,"Xr3_Vz",17,23,104
    SUV_1,"Xr3_Vz",17,24,105
    SUV_1,"Xr3_Vz",17,30,106
    SUV_1,"Xr3_Vz",17,3,113
    SUV_1,"Xr3_Vz",17,1,999
    SUV_1,"Xr3_Vz",18,1,1
    SUV_1,"Xr3_Vz",18,2,101
    SUV_1,"Xr3_Vz",18,1,102
    SUV_1,"Xr3_Vz",18,79,104
    SUV_1,"Xr3_Vz",18,15,105
    SUV_1,"Xr3_Vz",18,5,106
    SUV_1,"Xr3_Vz",18,1,109
    SUV_1,"Xr3_Vz",18,2,113
    SUV_1,"Xr3_Vz",18,2,999
    SUV_1,"Xr3_Vz",19,1,1
    SUV_1,"Xr3_Vz",19,4,101
    SUV_1,"Xr3_Vz",19,496,104
    SUV_1,"Xr3_Vz",19,11,105
    SUV_1,"Xr3_Vz",19,4,106
    SUV_1,"Xr3_Vz",19,1,109
    SUV_1,"Xr3_Vz",19,1,113
    SUV_1,"Xr3_Vz",20,2,102
    SUV_1,"Xr3_Vz",20,243,104
    SUV_1,"Xr3_Vz",20,14,105
    SUV_1,"Xr3_Vz",20,5,109
    SUV_1,"Xr3_Vz",20,4,112
    SUV_1,"Xr3_Vz",20,11,113
    SUV_1,"Xr3_Vz",20,1,3
    SUV_1,"Xr3_Vz",20,1,999
    SUV_1,"Xr3_Vz",21,1,1
    SUV_1,"Xr3_Vz",21,1,101
    SUV_1,"Xr3_Vz",21,1,104
    SUV_1,"Xr3_Vz",21,10,105
    SUV_1,"Xr3_Vz",21,1,106
    SUV_1,"Xr3_Vz",21,6,109
    SUV_1,"Xr3_Vz",21,2,113
    SUV_1,"Xr3_Vz",21,2,999
    SUV_1,"Xr3_Vz",22,4,101
    SUV_1,"Xr3_Vz",22,1,104
    SUV_1,"Xr3_Vz",22,8,105
    SUV_1,"Xr3_Vz",22,1,106
    SUV_1,"Xr3_Vz",22,5,113
    SUV_1,"Xr3_Vz",23,1,1
    SUV_1,"Xr3_Vz",23,2,101
    SUV_1,"Xr3_Vz",23,4,104
    SUV_1,"Xr3_Vz",23,14,105
    SUV_1,"Xr3_Vz",23,10,106
    SUV_1,"Xr3_Vz",23,8,113
    SUV_1,"Xr3_Vz",23,8,999
    SUV_1,"Xr3_Vz",24,3,101
    SUV_1,"Xr3_Vz",24,2,102
    SUV_1,"Xr3_Vz",24,3,104
    SUV_1,"Xr3_Vz",24,11,105
    SUV_1,"Xr3_Vz",24,2,106
    SUV_1,"Xr3_Vz",24,1,3
    SUV_1,"Xr3_Vz",25,3,101
    SUV_1,"Xr3_Vz",25,1,102
    SUV_1,"Xr3_Vz",25,1,103
    SUV_1,"Xr3_Vz",25,6,104
    SUV_1,"Xr3_Vz",25,22,105
    SUV_1,"Xr3_Vz",25,6,106
    SUV_1,"Xr3_Vz",25,2,109
    SUV_1,"Xr3_Vz",25,2,110
    SUV_1,"Xr3_Vz",25,1,112
    SUV_1,"Xr3_Vz",25,1,113
    SUV_1,"Xr3_Vz",25,2,3
    SUV_1,"Xr3_Vz",26,2,1
    SUV_1,"Xr3_Vz",26,3,101
    SUV_1,"Xr3_Vz",26,1,102
    SUV_1,"Xr3_Vz",26,2,104
    SUV_1,"Xr3_Vz",26,21,105
    SUV_1,"Xr3_Vz",26,8,106
    SUV_1,"Xr3_Vz",26,1,107
    SUV_1,"Xr3_Vz",26,3,110
    SUV_1,"Xr3_Vz",26,1,112
    SUV_1,"Xr3_Vz",26,3,113
    SUV_1,"Xr3_Vz",26,12,999
    SUV_1,"Xr3_Vz",27,2,101
    SUV_1,"Xr3_Vz",27,1,102
    SUV_1,"Xr3_Vz",27,9,105
    SUV_1,"Xr3_Vz",27,2,106
    SUV_1,"Xr3_Vz",27,2,110
    SUV_1,"Xr3_Vz",27,1,113
    SUV_1,"Xr3_Vz",28,2,1
    SUV_1,"Xr3_Vz",28,6,101
    SUV_1,"Xr3_Vz",28,2,102
    SUV_1,"Xr3_Vz",28,3,104
    SUV_1,"Xr3_Vz",28,29,105
    SUV_1,"Xr3_Vz",28,10,106
    SUV_1,"Xr3_Vz",28,1,110
    SUV_1,"Xr3_Vz",28,2,113
    SUV_1,"Xr3_Vz",29,2,1
    SUV_1,"Xr3_Vz",29,5,101
    SUV_1,"Xr3_Vz",29,2,102
    SUV_1,"Xr3_Vz",29,2,104
    SUV_1,"Xr3_Vz",29,8,105
    SUV_1,"Xr3_Vz",29,11,106
    SUV_1,"Xr3_Vz",29,6,113
    SUV_1,"Xr3_Vz",29,2,999
    SUV_1,"Xr3_Vz",30,2,101
    SUV_1,"Xr3_Vz",30,2,104
    SUV_1,"Xr3_Vz",30,1,105
    SUV_1,"Xr3_Vz",30,1,106
    SUV_1,"Xr3_Vz",30,1,112
    SUV_1,"Xr3_Vz",30,4,113
    SUV_1,"Xr3_Vz",31,1,101
    SUV_1,"Xr3_Vz",31,1,104
    SUV_1,"Xr3_Vz",31,1,105
    SUV_1,"Xr3_Vz",31,1,502
    SUV_1,"Xr3_Vz",31,4,999
    SUV_1,"Xr3_Vz",32,4,105
    SUV_1,"Xr3_Vz",32,1,109
    SUV_1,"Xr3_Vz",32,1,112
    SUV_1,"Xr3_Vz",32,37,113
    Je voudrais récupérer chaque valeur unique de la colonne 'CodeNCC', puis pour chaque valeur unique 'CodeNCC' récupérer par semaine les valeurs associées 'QtyByNCCcode' pour pouvoir faire une boucle pour obtenir:

    name: 'CodeNCC'
    data: 'Valeur QtyByNCCcode',

    La quantité de data correspond au nombre de semaine de l'année (ici 32), donc 1 valeur par semaine (bien sûr si pas de valeur, on retourne 0...)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    series: [{
                name: '113',
                data: [4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,12,123,32,4,0,4,12,123]
     
            }, {
                name: '104',
                data: [2,21,43,43,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,12,123,32,0,4,12,123]
     
            }, {
                name: '101',
                data: [2,43,35,23,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,32,12,123,32,0,4,12,123]
     
            }, {
                name: '102',
                data: [1,0,0,0,4,12,123,32,4,12,123,32,4,12,123,32,4,12,123,324,12,123,32,12,123,32,4,0,4,12,123]
     
            }]
    J'arrive à faire la mise en forme mais je ne réussi pas à récupérer les valeurs correctes des data...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    foreach($NumNccUnique as $NumNccUnique2){
    		echo "name: '".$NumNccUnique2['ErrorNumber']."',".'<br>';
    			echo "data: [";
    			foreach($NumQtyNCC as $NumQtyNCC1){
    				echo $NumQtyNCC1['QtyByNCCcode'].",";
    	}
    	echo "]";
    	echo '<br>';
    }
    Pour obtenir:


    Merci par avance
    Images attachées Images attachées  

  5. #5
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Le code que je propose n'a pas la prétention de faire exactement ce que veux obtenir mais sert à montrer que tu peux faire ce que tu veux faire sans passer par un tableau ayant pour clé le codeNCC mais directement à partir de la base de données triée de la bonne manière.

    Dans mon script, la table s'appelle table3.

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    <?php
    header('Content-type: image/png');
    $largeur = 1800;
    $hauteur = 800;
    $image   = imagecreatetruecolor($largeur, $hauteur);
    $fond    = imagecolorallocate($image, 255, 255, 255);
    imagefilledrectangle($image,0 , 0, $largeur, $hauteur, $fond);
    //---- Paramètres BDD
    define('DB_HOST', '127.0.0.1');
    define('DB_NAME', 'tests');
    define('DB_USER', 'root');
    define('DB_PWD' , '');
    $pdo    = new PDO("mysql:host=".DB_HOST."; dbname=".DB_NAME,DB_USER,DB_PWD, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
    //------ DEBUT
    $query  = "SELECT Semaine, CodeNCC, QtyByNCCcode FROM table3 where CodeNCC in (101, 102, 104, 113) order by Semaine, CodeNCC desc";
    //$query  = "SELECT Semaine, CodeNCC, QtyByNCCcode FROM table3 order by Semaine, CodeNCC desc";
    $sth    = $pdo->prepare($query);
    $sth->execute();
    $arraySemCode        = array();
    $arraySemTotal       = array();
    $arrayNCCCodeCouleur = array();
    while (list($Semaine, $CodeNCC, $QtyByNCCcode) = $sth->fetch(PDO::FETCH_NUM)) 
    {
     $arraySemCode[$Semaine][$CodeNCC] = $QtyByNCCcode;
     //---- Total semaine
     if (!isset($arraySemTotal[$Semaine])) {
      $arraySemTotal[$Semaine] = 0;
     }
     $arraySemTotal[$Semaine]       = $arraySemTotal[$Semaine] + $QtyByNCCcode;
     //---- Tableau des codes couleurs
     $arrayNCCCodeCouleur[$CodeNCC] = "";
    }
    //----- FIN
    //---- Affectation des couleurs
    $arrayCouleurs = array("FFEBCD","0000FF","8A2BE2","A52A2A","DEB887","5F9EA0","7FFF00","D2691E","FF7F50","6495ED","FFF8DC",
    "DC143C","00008B","008B8B","B8860B","A9A9A9","006400","BDB76B","8B008B","556B2F","FF8C00","9932CC",
    "8B0000","E9967A","8FBC8F","483D8B","2F4F4F","00CED1","9400D3","FF1493","00BFFF","696969","1E90FF",
    "D19275","B22222","FFFAF0","228B22","FF00FF","DCDCDC");
    $i = 0;
    foreach($arrayNCCCodeCouleur as $keyNCCCodeCouleur => $value)
    {
     $arrayNCCCodeCouleur[$keyNCCCodeCouleur] = $arrayCouleurs[$i];
     $i++;
    }
    //---- Dessin de l'image
    $noir           = imagecolorallocate($image, 0, 0, 0);
    $margeYBasse    = 20;
    $margeYHaute    = 40;
    $margeXGauche   = 10;
    $largeurHisto   = 25;
    $espacement     = 10;
    $positionXDebut = 10;
    foreach($arraySemTotal as $keySemTotal => $TotalSemaine)
    {
     $positionYDebut = $margeYBasse;
     foreach($arraySemCode[$keySemTotal] as $keyNCCCode => $QtyByNCCcode) {
      $rgb      = $arrayNCCCodeCouleur[$keyNCCCode];
      //PRINT $rgb." ";
      $couleur  = imagecolorallocate($image, hexdec(substr($rgb, 0, 2)), hexdec(substr($rgb, 2, 2)), hexdec(substr($rgb, 4, 2)));
      $pourcent = ($QtyByNCCcode / $TotalSemaine);
      $pixels   = ($hauteur - $margeYBasse - $margeYHaute) * $pourcent;
     
      imagefilledrectangle($image,$positionXDebut, $positionYDebut, $positionXDebut+$largeurHisto, $positionYDebut+$pixels, $couleur);  
     
      $positionYDebut = $positionYDebut + $pixels;
     }
     imagestring($image,3, $positionXDebut,$hauteur-$margeYBasse, $keySemTotal, $noir);
     $positionXDebut = $positionXDebut + $espacement+$largeurHisto;
     //break;
    }
    //---- Envoie le flux de l'image
    imagepng($image);
    //---- Desalloue la memoire utilisée par l'image
    imagedestroy($image);

    Donne


    Nom : Capture20170817_001.JPG
Affichages : 816
Taille : 90,8 Ko
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  6. #6
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    Merci, mais je préfère rester sur le standard de 'highcharts'.

    C'est quand même fou, j'ai beau tourner le problème dans tout les sens, je n'y arrive pas avec les for...

    Voici mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    $ParetoNCC = $pdo->query("SELECT Line, CSL, Week(ProcessDate - interval 5 hour, 3) As Semaine, ErrorNumber, COUNT(*) AS QTY FROM nccdetails WHERE LEFT(ProcessDate, 4)='".$sYEAR."' AND Line = '".$Ligne."' AND '".$Cellule."' IN(CSL, 'Cellule') GROUP BY Line, CSL, ErrorNumber, Semaine ORDER BY Semaine;");
    $ParetoNCC->execute();
    $ParetoNCC=$ParetoNCC->fetchAll();
    //var_dump($ParetoNCC);
     
    $CodeNCCUnique=array_column($ParetoNCC, 'ErrorNumber');
    $CodeNCCUnique=array_unique($CodeNCCUnique);
    $CodeNCCUnique=array_values($CodeNCCUnique);
    //var_dump($CodeNCCUnique);
     
    $WeeksUniqueDB=array_column($ParetoNCC, 'Semaine');
    $WeeksUniqueDB=array_unique($WeeksUniqueDB);
    $WeeksUniqueDB=array_values($WeeksUniqueDB);
    //var_dump($WeeksUniqueDB);
     
    $aHighChartsSeries=array();
    $sHighChartsSeries='';
     
    //	+------+-----+-------+-------------+-----+
    //	| Line | CSL | Weeks | ErrorNumber | QTY |
    //	+------+-----+-------+-------------+-----+
     
    for($a=0; $a<sizeof($CodeNCCUnique); $a++){
    	echo "<b>Code NCC: </b>".$CodeNCCUnique[$a].'<br>';
    	$sHighChartsSeries=$sHighChartsSeries."{".'<br>';
    	$sHighChartsSeries=$sHighChartsSeries."name: '".$CodeNCCUnique[$a]."'".'<br>';
    	$sHighChartsSeries=$sHighChartsSeries."data: [";
    	for($b=0; $b<sizeof($ParetoNCC); $b++){
    		for($c=0; $c<sizeof($WeeksUniqueDB); $c++){
    			if($WeeksUniqueDB[$c][0]=$ParetoNCC[$b][2]&&$ParetoNCC[$b][3]=$CodeNCCUnique[$a]){
    				echo $CodeNCCUnique[$a].",";
     
    			};//FIN if	
    												  };//FIN for $c
    		                                   };//FIN for $b
     
    	$sHighChartsSeries=$sHighChartsSeries."]".'<br>';
    	$sHighChartsSeries=$sHighChartsSeries."}, ".'<br>';
     
    };//FIN for $a
    Ce qui me donne comme résultat (en fonction des valeurs de ma combobox):

    PEJ9SzP-1 | 68 - PreProcess | 1 | 999 | 1
    PEJ9SzP-1 | 68 - PreProcess | 1 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 3 | 1 | 2
    PEJ9SzP-1 | 68 - PreProcess | 3 | 999 | 1
    PEJ9SzP-1 | 68 - PreProcess | 4 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 7 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 12 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 12 | 3 | 1
    PEJ9SzP-1 | 68 - PreProcess | 14 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 17 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 21 | 3 | 1
    PEJ9SzP-1 | 68 - PreProcess | 25 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 26 | 999 | 7
    PEJ9SzP-1 | 68 - PreProcess | 27 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 30 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 31 | 1 | 1
    PEJ9SzP-1 | 68 - PreProcess | 33 | 1 | 1

    Je voudrais trouver une imbrication pour arriver au résultat:

    {
    name: '999',
    data: [1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0]
    },{
    name: '1',
    data: [1,0,2,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,1,0,1]
    },{
    name: '3',
    data: [2,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0]
    }

    Merci par avance

  7. #7
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    J'ai dû mal m'exprimer. Ne regarde pas le résultat mais le moyen d'y arriver.
    La requête SQL et le while qui suit. La génération de l'image c'est seulement pour montrer l'exploitation de ce qui est fait avant.
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  8. #8
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    Ok, j'essai mais je ne récupère rien...

    Ma requête:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    $ParetoNCC = $pdo->query("SELECT Line, CSL, Week(ProcessDate - interval 5 hour, 3) As Semaine, ErrorNumber, COUNT(*) AS QTY FROM nccdetails WHERE LEFT(ProcessDate, 4)='".$sYEAR."' AND Line = '".$Ligne."' AND '".$Cellule."' IN(CSL, 'Cellule') GROUP BY Line, CSL, ErrorNumber, Semaine ORDER BY Semaine;");
    $ParetoNCC->execute();
    $ParetoNCC=$ParetoNCC->fetchAll();
    Mon code (copié/collé):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    $arraySemCode        = array();
    $arraySemTotal       = array();
    $arrayNCCCodeCouleur = array();
     
    while (list($Line, $CSL, $Semaine, $CodeNCC, $QtyByNCCcode)=each($ParetoNCC));
    {
    $arraySemCode[$Semaine][$CodeNCC] = $QtyByNCCcode;
     
    //---- Total semaine
    if (!isset($arraySemTotal[$Semaine])) {
    $arraySemTotal[$Semaine] = 0;
    }
    $arraySemTotal[$Semaine]       = $arraySemTotal[$Semaine] + $QtyByNCCcode; 
    }
    var_dump($arraySemTotal);
    Je ne suis pas sur de:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    while (list($Line, $CSL, $Semaine, $CodeNCC, $QtyByNCCcode)=each($ParetoNCC));

  9. #9
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    Je reviens, je réussi bien à récupérer les valeurs

    Mon var_dump me retourne:
    Pièce jointe 307997

    J'ai presque réussi... mais... Du coup j'ai pris le problème différemment lol.

    Mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $aResult = array();
    //$test=array();
    $VarNull="0";
     
    while (list($Line, $CSL, $Semaine, $ErrorNumber, $QTY) = $ParetoNCC->fetch(PDO::FETCH_NUM)) 
    {
    	$sHighChartsSeries=$sHighChartsSeries."{";
    	$sHighChartsSeries=$sHighChartsSeries."name: '".$ErrorNumber."', ";
    	$sHighChartsSeries=$sHighChartsSeries."data: [";
    for($a=0;$a<sizeof($Weeks);$a++){
    	//$test[$ErrorNumber][$Semaine]=$QTY;
    	if($Weeks[$a][0]==$Semaine){
    		$aResult[$ErrorNumber][$Semaine] = $QTY;
    		$sHighChartsSeries=$sHighChartsSeries.$QTY.',';
    		}
    	else{
    		//array_push($aResult, $aResult[$ErrorNumber][$Weeks[$a][0]] = $VarNull);
    		$aResult[$ErrorNumber][$Weeks[$a][0]] = $VarNull;
    		$sHighChartsSeries=$sHighChartsSeries.$VarNull.',';
    		};
     
    	};
    	$sHighChartsSeries=rtrim($sHighChartsSeries, ",");
    	$sHighChartsSeries=$sHighChartsSeries."]";
    	$sHighChartsSeries=$sHighChartsSeries."},";
     
     
    };
     
    var_dump($aResult);
    Ce qui me retourne:

    Mais ça me groupe pas en fonction des codes ncc (exemple le code ncc = 3, je devrais avoir 19, 20, 33, or je n'ai que 33...)
    Images attachées Images attachées       

  10. #10
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    Ça avance... Je suis 'presque' arrivé à mon objectif...

    Mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $aResult = array();
    $VarNull="0";
    while (list($Line, $CSL, $Semaine, $ErrorNumber, $QTY) = $ParetoNCC->fetch(PDO::FETCH_NUM)) 
    {
    for($a=0;$a<sizeof($Weeks);$a++){
    	if($Weeks[$a][0]==$Semaine){
    		$aResult[$ErrorNumber][$Semaine] = $QTY;
    		$sHighChartsSeriesValues=$sHighChartsSeriesValues.$QTY.',';}
    	else{
    		$aResult[$ErrorNumber][$Weeks[$a][0]] = $VarNull;
    		$sHighChartsSeriesValues=$sHighChartsSeriesValues.$VarNull.',';;
    	}
    }
    goto fill;
    };
     
    fill:
    foreach($aResult as $keyNCCCode => $value){
    	$sHighChartsSeries=$sHighChartsSeries."{";
    	$sHighChartsSeries=$sHighChartsSeries."name: '".$keyNCCCode."', ";
    	$sHighChartsSeries=$sHighChartsSeries."data: [";
    	for($b=0; $b<sizeof($keyNCCCode);$b++){
    		$sHighChartsSeries=$sHighChartsSeries.$sHighChartsSeriesValues;
     
    	}
    	$sHighChartsSeries=rtrim($sHighChartsSeries, ",");
    	$sHighChartsSeries=$sHighChartsSeries."]";
    	$sHighChartsSeries=$sHighChartsSeries."},";
    };
    echo rtrim($sHighChartsSeries, ",");
    J'arrive bien au résultat que je désire mais ça ne boucle pas comme je le voudrais, ça ne boucle qu'une fois, à cause du goto je pense...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    series: [{name: '999', data: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}]
    Merci par avance.

  11. #11
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    un p'tit coup de pouce, j'ai juste ce souis pour clore mon projet.

    merci par avance

  12. #12
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Salut,

    bon j'ai regardé rapidement et je n'ai pas tout compris dans ton algo ni tes explications
    J'aurais fait beaucoup plus simple en partant de tes données d'exemple cela donnerait (pour ce que j'ai compris) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    $data = [
        ['SUV_1','Xr3_Vz',1,1,1],
        ['SUV_1','Xr3_Vz',1,3,101],
        ['SUV_1','Xr3_Vz',1,4,102],
        ['SUV_1','Xr3_Vz',1,27,104],
        ['SUV_1','Xr3_Vz',1,53,105],
        ['SUV_1','Xr3_Vz',1,18,106],
        ['SUV_1','Xr3_Vz',1,1,107],
        ['SUV_1','Xr3_Vz',1,1,999],
        ['SUV_1','Xr3_Vz',2,2,101],
        ['SUV_1','Xr3_Vz',2,4,102],
        ['SUV_1','Xr3_Vz',2,30,104],
        ['SUV_1','Xr3_Vz',2,20,105],
        ['SUV_1','Xr3_Vz',2,8,106],
        ['SUV_1','Xr3_Vz',2,1,109],
        ['SUV_1','Xr3_Vz',2,3,113],
        ['SUV_1','Xr3_Vz',2,1,3],
        ['SUV_1','Xr3_Vz',2,8,999],
        ['SUV_1','Xr3_Vz',3,7,101],
        ['SUV_1','Xr3_Vz',3,1,102],
        ['SUV_1','Xr3_Vz',3,13,104],
        ['SUV_1','Xr3_Vz',3,21,105],
        ['SUV_1','Xr3_Vz',3,9,106],
        ['SUV_1','Xr3_Vz',3,1,999],
        ['SUV_1','Xr3_Vz',4,14,101],
        ['SUV_1','Xr3_Vz',4,12,104],
        ['SUV_1','Xr3_Vz',4,12,105],
        ['SUV_1','Xr3_Vz',4,3,106],
        ['SUV_1','Xr3_Vz',4,2,110],
        ['SUV_1','Xr3_Vz',4,4,113],
        ['SUV_1','Xr3_Vz',4,1,999],
        ['SUV_1','Xr3_Vz',5,5,101],
        ['SUV_1','Xr3_Vz',5,3,104],
        ['SUV_1','Xr3_Vz',5,7,105],
        ['SUV_1','Xr3_Vz',5,5,106],
        ['SUV_1','Xr3_Vz',5,2,110],
        ['SUV_1','Xr3_Vz',6,2,101],
        ['SUV_1','Xr3_Vz',6,4,102],
        ['SUV_1','Xr3_Vz',6,2,103],
        ['SUV_1','Xr3_Vz',6,4,104],
        ['SUV_1','Xr3_Vz',6,5,105],
        ['SUV_1','Xr3_Vz',6,4,106],
        ['SUV_1','Xr3_Vz',6,1,110],
        ['SUV_1','Xr3_Vz',7,1,1],
        ['SUV_1','Xr3_Vz',7,5,101],
        ['SUV_1','Xr3_Vz',7,1,102],
        ['SUV_1','Xr3_Vz',7,4,104],
        ['SUV_1','Xr3_Vz',7,21,105],
        ['SUV_1','Xr3_Vz',7,6,106],
        ['SUV_1','Xr3_Vz',7,2,110],
        ['SUV_1','Xr3_Vz',7,1,112],
        ['SUV_1','Xr3_Vz',7,1,113],
        ['SUV_1','Xr3_Vz',8,1,101],
        ['SUV_1','Xr3_Vz',8,4,102],
        ['SUV_1','Xr3_Vz',8,1,103],
        ['SUV_1','Xr3_Vz',8,19,104],
        ['SUV_1','Xr3_Vz',8,9,105],
        ['SUV_1','Xr3_Vz',8,11,106],
        ['SUV_1','Xr3_Vz',8,1,109],
        ['SUV_1','Xr3_Vz',8,1,110],
        ['SUV_1','Xr3_Vz',8,5,113],
        ['SUV_1','Xr3_Vz',9,2,101],
        ['SUV_1','Xr3_Vz',9,2,102],
        ['SUV_1','Xr3_Vz',9,1,103],
        ['SUV_1','Xr3_Vz',9,45,104],
        ['SUV_1','Xr3_Vz',9,10,105],
        ['SUV_1','Xr3_Vz',9,2,106],
        ['SUV_1','Xr3_Vz',9,1,109],
        ['SUV_1','Xr3_Vz',9,2,110],
        ['SUV_1','Xr3_Vz',9,2,113],
        ['SUV_1','Xr3_Vz',9,2,999],
        ['SUV_1','Xr3_Vz',10,4,104],
        ['SUV_1','Xr3_Vz',10,6,105],
        ['SUV_1','Xr3_Vz',10,5,106],
        ['SUV_1','Xr3_Vz',10,3,113],
        ['SUV_1','Xr3_Vz',11,1,101],
        ['SUV_1','Xr3_Vz',11,1,102],
        ['SUV_1','Xr3_Vz',11,6,104],
        ['SUV_1','Xr3_Vz',11,22,105],
        ['SUV_1','Xr3_Vz',11,10,106],
        ['SUV_1','Xr3_Vz',11,1,109],
        ['SUV_1','Xr3_Vz',11,1,110],
        ['SUV_1','Xr3_Vz',11,1,112],
        ['SUV_1','Xr3_Vz',11,8,113],
        ['SUV_1','Xr3_Vz',11,4,999],
        ['SUV_1','Xr3_Vz',12,7,101],
        ['SUV_1','Xr3_Vz',12,3,102],
        ['SUV_1','Xr3_Vz',12,1,103],
        ['SUV_1','Xr3_Vz',12,8,104],
        ['SUV_1','Xr3_Vz',12,20,105],
        ['SUV_1','Xr3_Vz',12,4,106],
        ['SUV_1','Xr3_Vz',12,5,113],
        ['SUV_1','Xr3_Vz',12,1,999],
        ['SUV_1','Xr3_Vz',13,2,102],
        ['SUV_1','Xr3_Vz',13,16,104],
        ['SUV_1','Xr3_Vz',13,33,105],
        ['SUV_1','Xr3_Vz',13,1,106],
        ['SUV_1','Xr3_Vz',13,2,107],
        ['SUV_1','Xr3_Vz',13,2,109],
        ['SUV_1','Xr3_Vz',13,1,112],
        ['SUV_1','Xr3_Vz',13,7,113],
        ['SUV_1','Xr3_Vz',13,1,999],
        ['SUV_1','Xr3_Vz',14,4,101],
        ['SUV_1','Xr3_Vz',14,3,102],
        ['SUV_1','Xr3_Vz',14,1,103],
        ['SUV_1','Xr3_Vz',14,3,104],
        ['SUV_1','Xr3_Vz',14,92,105],
        ['SUV_1','Xr3_Vz',14,20,106],
        ['SUV_1','Xr3_Vz',14,1,109],
        ['SUV_1','Xr3_Vz',14,2,113],
        ['SUV_1','Xr3_Vz',14,2,3],
        ['SUV_1','Xr3_Vz',14,1,999],
        ['SUV_1','Xr3_Vz',15,3,102],
        ['SUV_1','Xr3_Vz',15,52,104],
        ['SUV_1','Xr3_Vz',15,48,105],
        ['SUV_1','Xr3_Vz',15,1,106],
        ['SUV_1','Xr3_Vz',15,6,113],
        ['SUV_1','Xr3_Vz',16,2,101],
        ['SUV_1','Xr3_Vz',16,2,102],
        ['SUV_1','Xr3_Vz',16,6,104],
        ['SUV_1','Xr3_Vz',16,70,105],
        ['SUV_1','Xr3_Vz',16,28,106],
        ['SUV_1','Xr3_Vz',16,6,113],
        ['SUV_1','Xr3_Vz',16,2,999],
        ['SUV_1','Xr3_Vz',17,2,101],
        ['SUV_1','Xr3_Vz',17,3,102],
        ['SUV_1','Xr3_Vz',17,23,104],
        ['SUV_1','Xr3_Vz',17,24,105],
        ['SUV_1','Xr3_Vz',17,30,106],
        ['SUV_1','Xr3_Vz',17,3,113],
        ['SUV_1','Xr3_Vz',17,1,999],
        ['SUV_1','Xr3_Vz',18,1,1],
        ['SUV_1','Xr3_Vz',18,2,101],
        ['SUV_1','Xr3_Vz',18,1,102],
        ['SUV_1','Xr3_Vz',18,79,104],
        ['SUV_1','Xr3_Vz',18,15,105],
        ['SUV_1','Xr3_Vz',18,5,106],
        ['SUV_1','Xr3_Vz',18,1,109],
        ['SUV_1','Xr3_Vz',18,2,113],
        ['SUV_1','Xr3_Vz',18,2,999],
        ['SUV_1','Xr3_Vz',19,1,1],
        ['SUV_1','Xr3_Vz',19,4,101],
        ['SUV_1','Xr3_Vz',19,496,104],
        ['SUV_1','Xr3_Vz',19,11,105],
        ['SUV_1','Xr3_Vz',19,4,106],
        ['SUV_1','Xr3_Vz',19,1,109],
        ['SUV_1','Xr3_Vz',19,1,113],
        ['SUV_1','Xr3_Vz',20,2,102],
        ['SUV_1','Xr3_Vz',20,243,104],
        ['SUV_1','Xr3_Vz',20,14,105],
        ['SUV_1','Xr3_Vz',20,5,109],
        ['SUV_1','Xr3_Vz',20,4,112],
        ['SUV_1','Xr3_Vz',20,11,113],
        ['SUV_1','Xr3_Vz',20,1,3],
        ['SUV_1','Xr3_Vz',20,1,999],
        ['SUV_1','Xr3_Vz',21,1,1],
        ['SUV_1','Xr3_Vz',21,1,101],
        ['SUV_1','Xr3_Vz',21,1,104],
        ['SUV_1','Xr3_Vz',21,10,105],
        ['SUV_1','Xr3_Vz',21,1,106],
        ['SUV_1','Xr3_Vz',21,6,109],
        ['SUV_1','Xr3_Vz',21,2,113],
        ['SUV_1','Xr3_Vz',21,2,999],
        ['SUV_1','Xr3_Vz',22,4,101],
        ['SUV_1','Xr3_Vz',22,1,104],
        ['SUV_1','Xr3_Vz',22,8,105],
        ['SUV_1','Xr3_Vz',22,1,106],
        ['SUV_1','Xr3_Vz',22,5,113],
        ['SUV_1','Xr3_Vz',23,1,1],
        ['SUV_1','Xr3_Vz',23,2,101],
        ['SUV_1','Xr3_Vz',23,4,104],
        ['SUV_1','Xr3_Vz',23,14,105],
        ['SUV_1','Xr3_Vz',23,10,106],
        ['SUV_1','Xr3_Vz',23,8,113],
        ['SUV_1','Xr3_Vz',23,8,999],
        ['SUV_1','Xr3_Vz',24,3,101],
        ['SUV_1','Xr3_Vz',24,2,102],
        ['SUV_1','Xr3_Vz',24,3,104],
        ['SUV_1','Xr3_Vz',24,11,105],
        ['SUV_1','Xr3_Vz',24,2,106],
        ['SUV_1','Xr3_Vz',24,1,3],
        ['SUV_1','Xr3_Vz',25,3,101],
        ['SUV_1','Xr3_Vz',25,1,102],
        ['SUV_1','Xr3_Vz',25,1,103],
        ['SUV_1','Xr3_Vz',25,6,104],
        ['SUV_1','Xr3_Vz',25,22,105],
        ['SUV_1','Xr3_Vz',25,6,106],
        ['SUV_1','Xr3_Vz',25,2,109],
        ['SUV_1','Xr3_Vz',25,2,110],
        ['SUV_1','Xr3_Vz',25,1,112],
        ['SUV_1','Xr3_Vz',25,1,113],
        ['SUV_1','Xr3_Vz',25,2,3],
        ['SUV_1','Xr3_Vz',26,2,1],
        ['SUV_1','Xr3_Vz',26,3,101],
        ['SUV_1','Xr3_Vz',26,1,102],
        ['SUV_1','Xr3_Vz',26,2,104],
        ['SUV_1','Xr3_Vz',26,21,105],
        ['SUV_1','Xr3_Vz',26,8,106],
        ['SUV_1','Xr3_Vz',26,1,107],
        ['SUV_1','Xr3_Vz',26,3,110],
        ['SUV_1','Xr3_Vz',26,1,112],
        ['SUV_1','Xr3_Vz',26,3,113],
        ['SUV_1','Xr3_Vz',26,12,999],
        ['SUV_1','Xr3_Vz',27,2,101],
        ['SUV_1','Xr3_Vz',27,1,102],
        ['SUV_1','Xr3_Vz',27,9,105],
        ['SUV_1','Xr3_Vz',27,2,106],
        ['SUV_1','Xr3_Vz',27,2,110],
        ['SUV_1','Xr3_Vz',27,1,113],
        ['SUV_1','Xr3_Vz',28,2,1],
        ['SUV_1','Xr3_Vz',28,6,101],
        ['SUV_1','Xr3_Vz',28,2,102],
        ['SUV_1','Xr3_Vz',28,3,104],
        ['SUV_1','Xr3_Vz',28,29,105],
        ['SUV_1','Xr3_Vz',28,10,106],
        ['SUV_1','Xr3_Vz',28,1,110],
        ['SUV_1','Xr3_Vz',28,2,113],
        ['SUV_1','Xr3_Vz',29,2,1],
        ['SUV_1','Xr3_Vz',29,5,101],
        ['SUV_1','Xr3_Vz',29,2,102],
        ['SUV_1','Xr3_Vz',29,2,104],
        ['SUV_1','Xr3_Vz',29,8,105],
        ['SUV_1','Xr3_Vz',29,11,106],
        ['SUV_1','Xr3_Vz',29,6,113],
        ['SUV_1','Xr3_Vz',29,2,999],
        ['SUV_1','Xr3_Vz',30,2,101],
        ['SUV_1','Xr3_Vz',30,2,104],
        ['SUV_1','Xr3_Vz',30,1,105],
        ['SUV_1','Xr3_Vz',30,1,106],
        ['SUV_1','Xr3_Vz',30,1,112],
        ['SUV_1','Xr3_Vz',30,4,113],
        ['SUV_1','Xr3_Vz',31,1,101],
        ['SUV_1','Xr3_Vz',31,1,104],
        ['SUV_1','Xr3_Vz',31,1,105],
        ['SUV_1','Xr3_Vz',31,1,502],
        ['SUV_1','Xr3_Vz',31,4,999],
        ['SUV_1','Xr3_Vz',32,4,105],
        ['SUV_1','Xr3_Vz',32,1,109],
        ['SUV_1','Xr3_Vz',32,1,112],
        ['SUV_1','Xr3_Vz',32,37,113]
    ];
     
    $nb_of_weeks = 0;
    array_map(function($v) use (&$nb_of_weeks) { $nb_of_weeks += ($v[2] - $nb_of_weeks) ?: 0; }, $data);
     
    $charts_model = array_fill(1, $nb_of_weeks, 0);   // zerofill
    $charts       = [];
     
    foreach ($data as [$line, $csl, $week, $qty, $ncc]) {
        if ( ! isset($charts[$ncc])) {
            $charts[$ncc] = $charts_model;
        }
     
        $charts[$ncc][$week] += $qty;
    }
     
    print_r($charts);

  13. #13
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    Nom : 2017-09-05_14h38_58.jpg
Affichages : 793
Taille : 81,4 Ko

    Mon code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    $aResult = array();
    $VarNull="0";
     
    while (list($Line, $CSL, $Semaine, $ErrorNumber, $QTY) = $ParetoNCC->fetch(PDO::FETCH_NUM)) 
    {
    for($a=0;$a<sizeof($Weeks);$a++){
    	if($Weeks[$a][0]==$Semaine){
    		$aResult[$ErrorNumber][$Semaine] = $QTY;
    		$sHighChartsSeriesValues=$sHighChartsSeriesValues.$QTY.',';}
    	else{
    		//$aResult[$ErrorNumber][$Weeks[$a][0]]= $VarNull; <- ICI CA NE FONCTIONNE PAS
    		$sHighChartsSeriesValues=$sHighChartsSeriesValues.$VarNull.',';;
    	}
    };
    };
     
    foreach($aResult as $keyNCCCode => $value){
    	$sHighChartsSeries=$sHighChartsSeries."{";
    	$sHighChartsSeries=$sHighChartsSeries."name: '".$keyNCCCode."', ";
    	$sHighChartsSeries=$sHighChartsSeries."data: [";
     
    	for($aa=0;$aa<sizeof($Weeks);$aa++){
     
    		//if($Weeks[$a][0]==$Semaine){
    		//	$sHighChartsSeries=$sHighChartsSeries.$aResult[$keyNCCCode][$Semaine].",";
    		//}
    		//else{
    		$sHighChartsSeries=$sHighChartsSeries.$aResult[$keyNCCCode][$Weeks[$aa][0]].",";
    		}
     
    	$sHighChartsSeries=rtrim($sHighChartsSeries, ",");
    	$sHighChartsSeries=$sHighChartsSeries."]";
    	$sHighChartsSeries=$sHighChartsSeries."},";
    };

  14. #14
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    437
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 437
    Points : 109
    Points
    109
    Par défaut
    C'et bon j'ai trouvé ^^
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    $aResult = array();
    $VarNull="0";
     
    while (list($Line, $CSL, $Semaine, $ErrorNumber, $QTY) = $ParetoNCC->fetch(PDO::FETCH_NUM)) 
    {
    for($a=0;$a<sizeof($Weeks);$a++){
    	if($Weeks[$a][0]==$Semaine){
    		$aResult[$ErrorNumber][$Semaine] = $QTY;
    		$sHighChartsSeriesValues=$sHighChartsSeriesValues.$QTY.',';}
    	else{
    		$sHighChartsSeriesValues=$sHighChartsSeriesValues.$VarNull.',';};
    	}
    };
     
     
    foreach($aResult as $keyNCCCode => $value){
    	$sHighChartsSeries=$sHighChartsSeries."{";
    	$sHighChartsSeries=$sHighChartsSeries."name: '".$keyNCCCode."', ";
    	$sHighChartsSeries=$sHighChartsSeries."data: [";
     
    	for($aa=0;$aa<sizeof($Weeks);$aa++){
    		if(!isset($aResult[$keyNCCCode][$Weeks[$aa][0]])) {$aResult[$keyNCCCode][$Weeks[$aa][0]]= "0";};
    			$sHighChartsSeries=$sHighChartsSeries.$aResult[$keyNCCCode][$Weeks[$aa][0]].",";
    		};
     
    	$sHighChartsSeries=rtrim($sHighChartsSeries, ",");
    	$sHighChartsSeries=$sHighChartsSeries."]";
    	$sHighChartsSeries=$sHighChartsSeries."},";
    };

  15. #15
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    Salut,

    si tu t'étais inspiré de mon code, tu aurais fait beaucoup plus lisible :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    $chart_model = array_fill(1, $Weeks, 0);   // zerofill
    $chart_data   = [];
     
    while ([$line, $csl, $week, $ncc, $qty] = $ParetoNCC->fetch(PDO::FETCH_NUM)) {
        if ( ! isset($chart_data[$ncc])) {
            $chart_data[$ncc] = $chart_model;
        }
     
        $chart_data[$ncc][$week] += $qty;
    }
     
    $json = [];
    foreach ($chart_data as $ncc => $v) {
        $json[] = "{ name: '{$ncc}', data: [".implode(', ', $v)."]}";
    }
     
    $chart_datasource = implode(',', $json);
    je pense que l'on doit arriver au même résultat, non ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 10
    Dernier message: 07/01/2013, 11h25
  2. [OpenOffice][Tableur] formule pour récupération de données
    Par fransix dans le forum OpenOffice & LibreOffice
    Réponses: 14
    Dernier message: 07/12/2012, 09h36
  3. [Mission] recherche flasheur pour récupération de données
    Par lechatmachin dans le forum ActionScript 1 & ActionScript 2
    Réponses: 0
    Dernier message: 19/07/2011, 19h29
  4. [XL-2003] Croisement de fichiers pour récupération de données
    Par Taarzan dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 03/09/2010, 13h09
  5. Méthode Find pour récupération de données dans un tableau
    Par clem.villeneuve dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 20/06/2007, 15h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo