Problème d'array...

Le
Denis Beauregard
Bonjour,


Je vais chercher une série d'informations dans une base de données
mySQL. Certaines de ces valeurs sont nulles (chaîne vide) et je ne
veux afficher que les valeurs non nulles. De plus, Je veux commencer
à la 5e valeur jusqu'à la dernière.

Pourquoi ce code ne fonctionne pas comme il faut ?



function ADNY ($adny) {
$li = mysql_fetch_array ($rep);
$cles = array_keys ($li);
$max = count ($li);
$p = 0;
for ($i = 11; $i < $max; $i+=2) {
echo "(".$i.")".$li [$i+1]."=".$li [$i]."; ";
if ($li [$i] != "") {
}
}
return $adny;
}


La base de données contient 109 champs. print_r ($li); me donne ces
informations :


Array ( [0] => N113887 [kit] => N113887 [1] => xxx Cote [nom] => xxx
Cote [2] => Jean Costé/Côté, imm. 1635 [ancetre] => Jean Costé/Côté,
imm. 1635 [3] => France [pays] => France [4] => J2a4h2 [haplogroupe]
=> J2a4h2 [5] => 12 [DYS393] => 12 [6] => 23 [DYS390] => 23 [7] => 16
[DYS19] => 16 [8] => 10 [DYS391] => 10 [9] => 13-16 [DYS385] => 13-16
[10] => 11 [DYS426] => 11 [11] => 15 [DYS388] => 15 [12] => 11
[DYS439] => 11 [13] => 13 [DYS389i] => 13 [14] => 11 [DYS392] => 11
[15] => 30 [DYS389ii] => 30 [16] => 14 [DYS458] => 14 [17] => 8-9
[DYS459] => 8-9 [18] => 11 [DYS455] => 11 [19] => 11 [DYS454] => 11
[20] => 25 [DYS447] => 25 [21] => 15 [DYS437] => 15 [22] => 21
[DYS448] => 21 [23] => 30 [DYS449] => 30 [24] => 13-13-15-16 [DYS464]
=> 13-13-15-16 [25] => 12 [DYS460] => 12 [26] => 11 [Y-GATA-H4] => 11
[27] => 19-19 [YCAII] => 19-19 [28] => 14 [DYS456] => 14 [29] => 14
[DYS607] => 14 [30] => 17 [DYS576] => 17 [31] => 17 [DYS570] => 17
[32] => 34-38 [CDY] => 34-38 [33] => 12 [DYS442] => 12 [34] => 9
[DYS438] => 9 [35] => [DYS531] => [36] => [DYS578] => [37] =>
[DYF395S1] => [38] => [DYS590] => [39] => [DYS537] => [40] => [DYS641]
=> [41] => [DYS472] => [42] => [DYF406S1] => [43] => [DYS511] => [44]
=> [DYS425] => [45] => [DYS413] => [46] => [DYS557] => [47] =>
[DYS594] => [48] => [DYS436] => [49] => [DYS490] => [50] => [DYS534]
=> [51] => [DYS450] => [52] => [DYS444] => [53] => [DYS481] => [54] =>
[DYS520] => [55] => [DYS446] => [56] => [DYS617] => [57] => [DYS568]
=> [58] => [DYS487] => [59] => [DYS572] => [60] => [DYS640] => [61] =>
[DYS492] => [62] => [DYS565] => [63] => [DYS710] => [64] => [DYS485]
=> [65] => [DYS632] => [66] => [DYS495] => [67] => [DYS540] => [68] =>
[DYS714] => [69] => [DYS716] => [70] => [DYS717] => [71] => [DYS505]
=> [72] => [DYS556] => [73] => [DYS549] => [74] => [DYS589] => [75] =>
[DYS522] => [76] => [DYS494] => [77] => [DYS533] => [78] => [DYS636]
=> [79] => [DYS575] => [80] => [DYS638] => [81] => [DYS462] => [82] =>
[DYS452] => [83] => [DYS445] => [84] => [Y-GATA-A10] => [85] =>
[DYS463] => [86] => [DYS441] => [87] => [Y-GGAAT-1B07] => [88] =>
[DYS525] => [89] => [DYS712] => [90] => [DYS593] => [91] => [DYS650]
=> [92] => [DYS532] => [93] => [DYS715] => [94] => [DYS504] => [95] =>
[DYS513] => [96] => [DYS561] => [97] => [DYS552] => [98] => [DYS726]
=> [99] => [DYS635] => [100] => [DYS587] => [101] => [DYS643] => [102]
=> [DYS497] => [103] => [DYS510] => [104] => [DYS434] => [105] =>
[DYS461] => [106] => [DYS435] => [107] => 0 [dd] => 0 [108] => [de] =>
)


$max me donne 217, soit le double du nombre de cellules.

Quant à $cles, le contenu est celui-ci :

Array ( [0] => 0 [1] => kit [2] => 1 [3] => nom [4] => 2 [5] =>
ancetre [6] => 3 [7] => pays [8] => 4 [9] => haplogroupe [10] => 5
[11] => DYS393 [12] => 6 [13] => DYS390 [14] => 7 [15] => DYS19 [16]
=> 8 [17] => DYS391 [18] => 9 [19] => DYS385 [20] => 10 [21] => DYS426
[22] => 11 [23] => DYS388 [24] => 12 [25] => DYS439 [26] => 13 [27] =>
DYS389i [28] => 14 [29] => DYS392 [30] => 15 [31] => DYS389ii [32] =>
16 [33] => DYS458 [34] => 17 [35] => DYS459 [36] => 18 [37] => DYS455
[38] => 19 [39] => DYS454 [40] => 20 [41] => DYS447 [42] => 21 [43] =>
DYS437 [44] => 22 [45] => DYS448 [46] => 23 [47] => DYS449 [48] => 24
[49] => DYS464 [50] => 25 [51] => DYS460 [52] => 26 [53] => Y-GATA-H4
[54] => 27 [55] => YCAII [56] => 28 [57] => DYS456 [58] => 29 [59] =>
DYS607 [60] => 30 [61] => DYS576 [62] => 31 [63] => DYS570 [64] => 32
[65] => CDY [66] => 33 [67] => DYS442 [68] => 34 [69] => DYS438 [70]
=> 35 [71] => DYS531 [72] => 36 [73] => DYS578 [74] => 37 [75] =>
DYF395S1 [76] => 38 [77] => DYS590 [78] => 39 [79] => DYS537 [80] =>
40 [81] => DYS641 [82] => 41 [83] => DYS472 [84] => 42 [85] =>
DYF406S1 [86] => 43 [87] => DYS511 [88] => 44 [89] => DYS425 [90] =>
45 [91] => DYS413 [92] => 46 [93] => DYS557 [94] => 47 [95] => DYS594
[96] => 48 [97] => DYS436 [98] => 49 [99] => DYS490 [100] => 50 [101]
=> DYS534 [102] => 51 [103] => DYS450 [104] => 52 [105] => DYS444
[106] => 53 [107] => DYS481 [108] => 54 [109] => DYS520 [110] => 55
[111] => DYS446 [112] => 56 [113] => DYS617 [114] => 57 [115] =>
DYS568 [116] => 58 [117] => DYS487 [118] => 59 [119] => DYS572 [120]
=> 60 [121] => DYS640 [122] => 61 [123] => DYS492 [124] => 62 [125] =>
DYS565 [126] => 63 [127] => DYS710 [128] => 64 [129] => DYS485 [130]
=> 65 [131] => DYS632 [132] => 66 [133] => DYS495 [134] => 67 [135] =>
DYS540 [136] => 68 [137] => DYS714 [138] => 69 [139] => DYS716 [140]
=> 70 [141] => DYS717 [142] => 71 [143] => DYS505 [144] => 72 [145] =>
DYS556 [146] => 73 [147] => DYS549 [148] => 74 [149] => DYS589 [150]
=> 75 [151] => DYS522 [152] => 76 [153] => DYS494 [154] => 77 [155] =>
DYS533 [156] => 78 [157] => DYS636 [158] => 79 [159] => DYS575 [160]
=> 80 [161] => DYS638 [162] => 81 [163] => DYS462 [164] => 82 [165] =>
DYS452 [166] => 83 [167] => DYS445 [168] => 84 [169] => Y-GATA-A10
[170] => 85 [171] => DYS463 [172] => 86 [173] => DYS441 [174] => 87
[175] => Y-GGAAT-1B07 [176] => 88 [177] => DYS525 [178] => 89 [179] =>
DYS712 [180] => 90 [181] => DYS593 [182] => 91 [183] => DYS650 [184]
=> 92 [185] => DYS532 [186] => 93 [187] => DYS715 [188] => 94 [189] =>
DYS504 [190] => 95 [191] => DYS513 [192] => 96 [193] => DYS561 [194]
=> 97 [195] => DYS552 [196] => 98 [197] => DYS726 [198] => 99 [199] =>
DYS635 [200] => 100 [201] => DYS587 [202] => 101 [203] => DYS643 [204]
=> 102 [205] => DYS497 [206] => 103 [207] => DYS510 [208] => 104 [209]
=> DYS434 [210] => 105 [211] => DYS461 [212] => 106 [213] => DYS435
[214] => 107 [215] => dd [216] => 108 [217] => de )



Quel est le truc ? Je ne voudrais pas recopier les 100 clés dans
le code, surtout que d'autres pourraient s'ajouter


Denis
Vidéos High-Tech et Jeu Vidéo
Téléchargements
Vos réponses
Gagnez chaque mois un abonnement Premium avec GNT : Inscrivez-vous !
Trier par : date / pertinence
Otomatic
Le #25747582
Denis Beauregard écrivait :

Certaines de ces valeurs sont nulles (chaîne vide) et je ne
veux afficher que les valeurs non nulles.


Une chaîne vide n'est pas une valeur nulle.
NULL ne peut être testé (Pour MYSQL) que par IS NULL ou IS NOT NULL de
même qu'avec PHP, on doit tester par isnull()
--
Ce n'est pas parce que l'erreur se propage qu'elle devient vérité. Gandhi
Technologie aéronautique : http://aviatechno.net
Concorde dans la presse de 1965 à 2003 : http://le.pointu.free.fr
Denis Beauregard
Le #25747822
Le Mon, 28 Oct 2013 14:05:56 -0400, Denis Beauregard
fr.comp.lang.php:

Bonjour,


Je vais chercher une série d'informations dans une base de données
mySQL. Certaines de ces valeurs sont nulles (chaîne vide) et je ne
veux afficher que les valeurs non nulles. De plus, Je veux commencer
à la 5e valeur jusqu'à la dernière.



J'ai résolu mon problème en ré-écrivant complètement le code.

J'ai le nom des champs dans la ligne 1 et je lis donc cette ligne
au lieu de prendre le nom des clés dans la fonction array_keys qui
ne fonctionne pas comme je le voudrais !

Dommage que les fonctions mysql sont toutes désuettes. Cela va faire
beaucoup de code à corriger. Ils ont engagé des anciens de Microsoft ?


Denis
Publicité
Poster une réponse
Anonyme