Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2509 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Comment faire deux while optimisés

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment faire deux while optimisés

n°1919484
fourniey
Rendre au prochain
Posté le 28-08-2009 à 22:08:01  profilanswer
 

Bonjour,
 
Je veux récupérer quelques stats avec la même table en optimisant le tout; là, j'ai une erreur:
 
La première boucle fonctionne très bien.
 
Warning: oci_fetch_array() expects parameter 2 to be long, array given in
 
 
 

Code :
  1. $conn = oci_connect("php_fondation", "fokilfas", "prod" ) or die(Ora_Error($conn));
  2.  $cur = oci_parse($conn,"SELECT * FROM FON_PHP_STATUT_VUE where CD_STA_PERSONNE='$statut' and FIN_AN_STATUT='1858-11-17'" ) or die(Ora_Error($conn));
  3.   oci_execute($cur) or die(Ora_Error($conn));
  4.  $t_total = 0;
  5.  $t_oui = 0;
  6.  $t_non = 0;
  7.  $t_nr = 0;
  8.  $t_mess = 0;
  9.  while($detail = oci_fetch_array($cur)){
  10.   $t_total++;
  11.   switch ($detail[9]) {
  12.    case 'Oui':
  13.     $t_oui++;
  14.     break;
  15.    case 'Non':
  16.     $t_non++;
  17.     break;
  18.    case 'Message':
  19.     $t_mess++;
  20.     break;
  21.    default:
  22.     $t_nr++;
  23.     break;
  24.   }
  25.  $detail = array();
  26.  }
  27.  $cur = oci_parse($conn,"SELECT * FROM FON_PHP_STATUT_VUE where CD_STA_PERSONNE='$statut' and FIN_AN_STATUT='1858-11-17'" ) or die(Ora_Error($conn));
  28.   oci_execute($cur) or die(Ora_Error($conn));
  29.  $adr_tot = 0;
  30.  $adr_val = 0;
  31.  $adr_nv = 0;
  32.  $adr_t = 0;
  33.  $adr_x = 0;
  34.  while(oci_fetch_array($cur,$detail)){
  35.   $adr_tot++;
  36.   switch ($detail[15]) {
  37.    case 'V':
  38.     $adr_val++;
  39.     break;
  40.    case 'A':
  41.     $adr_nv++;
  42.     break;
  43.    case 'T':
  44.     $adr_t++;
  45.     break;
  46.    default:
  47.     $adr_x++;
  48.     break;
  49.   }
  50.  $detail = array();
  51.  }


Message édité par fourniey le 28-08-2009 à 22:08:16
mood
Publicité
Posté le 28-08-2009 à 22:08:01  profilanswer
 

n°1919509
stealth35
Posté le 29-08-2009 à 00:04:02  profilanswer
 

pourquoi ta mis :

 

while(oci_fetch_array($cur,$detail))

 

alors que tu la bien mis avant : $detail = oci_fetch_array($cur)

 

sinon si tu veux optimiser, fait une requete preparé avec t'es differente contidtion,  oci est bien plus rapide a parcourrir un tableau que PHP, utilise COUNT dans ta requete

 

en une dizaine de ligne tu pourrais faire ca


Message édité par stealth35 le 29-08-2009 à 00:10:33
n°1920000
fourniey
Rendre au prochain
Posté le 31-08-2009 à 17:14:01  profilanswer
 

Bonjour,
 
J'ai modifié la requête mais je ne réussis pas à afficher les résultats pourtant il y a des réponses.
 

Code :
  1. $t_oui = 0;
  2.  $t_non = 0;
  3.  $t_nr = 0;
  4.  $t_app = 0;
  5.  $t_att = 0;
  6.  $t_aut = 0;
  7.  $conn = oci_connect("php_fondation", "fokilfas", "prod" ) or die(Ora_Error($conn));
  8.  $cur = oci_parse($conn,"select  sum(case when fpsv.poste_occupe_fondation = 'NR' then 1 else 0 end) as nb_nr,
  9.         sum(case when fpsv.poste_occupe_fondation = 'Oui' then 1 else 0 end),
  10.         sum(case when fpsv.poste_occupe_fondation = 'Non' then 1 else 0 end) as nb_non,
  11.         sum(case when fpsv.poste_occupe_fondation = 'Message' then 1 else 0 end) as nb_appel,
  12.         sum(case when fpsv.poste_occupe_fondation is null then 1 else 0 end) as nb_attente,
  13.         sum(case when nvl(fpsv.poste_occupe_fondation,'NR') not in ('NR','Oui','Non','Message') then 1 else 0 end) as nb_autre
  14.  from  fon_php_statut_vue  fpsv
  15.  where  fpsv.cd_sta_personne = '163'" ) or die(Ora_Error($conn));
  16.   oci_execute($cur) or die(Ora_Error($conn));
  17.  oci_fetch_array($cur,$detail);
  18.  $detail = array();
  19. $t_oui = $detail[1];
  20. $t_non = $detail[2];
  21. $t_nr = $detail[0];
  22. $t_app = $detail[3];
  23. $t_att = $detail[4];
  24. $t_aut = $detail[5];


Message édité par fourniey le 31-08-2009 à 17:15:02
n°1920007
jeff@be
Posté le 31-08-2009 à 17:28:56  profilanswer
 

en ligne 17, ce n'est pas

Code :
  1. oci_fetch_array($cur,$detail);


mais

Code :
  1. $detail = oci_fetch_array($cur);


ensuite en ligne 18, tu vides ton array... supprime cette ligne.

n°1920010
fourniey
Rendre au prochain
Posté le 31-08-2009 à 17:34:56  profilanswer
 

ok, merci!
 
Je venais de corriger le $detail=...
 
et j'ai changé array pour row


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Comment faire deux while optimisés

 

Sujets relatifs
[Oracle & PHP] boucle if dans while : problèmeMise en forme d'une boucle while()
probleme avec 2 mysql_fetch_assoc dans une seule whileproblème boucle while
Boucle while imbriquéeQuestion toute bete, avec un While & For
deux whileIndentation Error dans boucle While
Aide boucle While Encore ?? je pete un cable ... :'(PHP - Portée d'1 variable (array) hors d'1 simple "while"
Plus de sujets relatifs à : Comment faire deux while optimisés


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR