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

Langage PHP Discussion :

[Système] function return echo


Sujet :

Langage PHP

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 158
    Par défaut [Système] function return echo
    bonjour,
    je ne comprend pas ...enfaite j'ai une fonction qui doit retourner 5 variables...mais impossible d'afficher ces variables dans ma pages ...alors que quand je fait echo...dans ma fonction et qu'ensuite j'apelle la fonction la variable est bien la !
    page de 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
     
    function consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,$i)
    {
    $query_consult = $dbconn_dns->query("select d.domainenom,cli.organisme,d.passdomaine,d.nic_expires,max(c.daterelance)from domaine_attente da, domainecoord d, client cli , commentaires c where d.idxdomaine = da.idxdomaine and d.asp=6 and d.qualification = 'C' and d.datecreation isnull and dateenregistrement isnull and da.idxattente = 1 and cli.numclient = d.numclient and chargeclientele = 5 and c.idxdomaine = d.idxdomaine group by d.domainenom,passdomaine,d.nic_expires,cli.organisme");
    $record_consult = $dbconn_dns->fetch_array($i, $query_consult);
    $domainenom = $record_consult[domainenom];
    $organisme = $record_consult[organisme];
    $passdomaine = $record_consult[passdomaine];
    $nic_expires = $record_consult[nic_expires];
    $max = $record_consult[max];	
    return $domainenom;
    return $organisme;
    return $passdomaine;
    return $nic_expires;
    return $max;
    }

    page normal
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
          <?php for ($i=0; $i != $nb ; $i++)
          {  consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,$i);?>
          <tr>
          <td class="result-pairrelief"> <? echo $domainenom; ?> </td>
          <td class="result-pairrelief"> <? echo  $organisme; ?> </td>
          <td class="result-pairrelief"> <?php echo  $passdomaine; ?> </td>
          <td class="result-pairrelief"> <?php echo  $nic_expires; ?> </td>
          <td class="result-pairrelief"> <?php echo  $max; ?> </td>
          <?
          }
          ?>
    Merci a tous...bizx!

  2. #2
    Membre éprouvé Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Par défaut
    salut essaye comme ça (j'ai pas testé).

    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
     
    <?php
    function consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,$i)
    {
    	$query_consult = $dbconn_dns->query("select d.domainenom,cli.organisme,d.passdomaine,d.nic_expires,max(c.daterelance)from domaine_attente da, domainecoord d, client cli , commentaires c where d.idxdomaine = da.idxdomaine and d.asp=6 and d.qualification = 'C' and d.datecreation isnull and dateenregistrement isnull and da.idxattente = 1 and cli.numclient = d.numclient and chargeclientele = 5 and c.idxdomaine = d.idxdomaine group by d.domainenom,passdomaine,d.nic_expires,cli.organisme");
    	$record_consult = $dbconn_dns->fetch_array($i, $query_consult);
    	return $record_consult;
    }
     
    for ($i=0; $i != $nb ; $i++)
    {
    	  $result = consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,$i);
    	  ?>
          <tr>
          <td class="result-pairrelief"> <?php echo  $result['$domainenom']; ?> </td>
          <td class="result-pairrelief"> <?php echo  $result['$organisme']; ?> </td>
          <td class="result-pairrelief"> <?php echo  $result['$passdomaine']; ?> </td>
          <td class="result-pairrelief"> <?php echo  $result['$nic_expires']; ?> </td>
          <td class="result-pairrelief"> <?php echo  $result['$max']; ?> </td>
    <?
    }
    ?>

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 158
    Par défaut
    j'avais déja essayé...mais " non" ca fonctionne pas !

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 158
    Par défaut
    Ralalala...Ca me stresse..j'essaie tout mes rien ne marche

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    69
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 69
    Par défaut
    tu ne peux renvoyer qu'une variable...

    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
     
    <?php
    function test() {
        $retour = array();
        $retour['premier_parametre'] = 'test1';
        $retour['second_parametre'] = 'test2';
        $retour['troisieme_parametre'] = 'test3';
        return $retour;
    }
     
    $a_afficher = test();
    echo $a_afficher['premier_parametre'],'<br />';
    echo $a_afficher['second_parametre'],'<br />';
    echo $a_afficher['troisieme_parametre'],'<br />';
    ?>
    c'est une methode pour renvoyer plusieurs resultats, tu les mets dans un tableau.
    tu peux aussi les mettre dans un objet.


    ta question est basique... revoie tes bases sur les fonctions, pour commencer

  6. #6
    Membre chevronné Avatar de sohnic
    Femme Profil pro
    bioinfo
    Inscrit en
    Mai 2003
    Messages
    426
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations professionnelles :
    Activité : bioinfo

    Informations forums :
    Inscription : Mai 2003
    Messages : 426
    Par défaut
    Bonjour,
    Une fonction ne retourne qu'une seule valeur, donc ca ne risque pas de marcher...

    Le fonctionnement general est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    function machin($arg1, $arg2)
    {
       //ce que fait la fonction
       //utilisation de $arg1, $arg2
       return $resultat_de_la_fonction
    }
     
    //dans le code
    $var=machin($val1,$val2);
    tu peux aussi avoir des fonctions sans argument ou/et qui ne retournent rien... je ne m'étalerai pas.

    Dans ton cas, le plus simple est de retourner un tableau qui contient l'ensemble des valeurs que tu souhaite afficher.

    Sinon, tu crées une classe et des méthodes...

    Bon courage,

    Sohnic

  7. #7
    Membre éprouvé Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Par défaut
    d'après ton premier code, la méthode $dbconn_dns->fetch_array($i, $query_consult); renvoie un tableau ($record_consult)
    Donc return $record_consult; doit fonctionner

    Peux tu nous poster le resultat de ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    function consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,$i)
    {
    	$query_consult = $dbconn_dns->query("select d.domainenom,cli.organisme,d.passdomaine,d.nic_expires,max(c.daterelance)from domaine_attente da, domainecoord d, client cli , commentaires c where d.idxdomaine = da.idxdomaine and d.asp=6 and d.qualification = 'C' and d.datecreation isnull and dateenregistrement isnull and da.idxattente = 1 and cli.numclient = d.numclient and chargeclientele = 5 and c.idxdomaine = d.idxdomaine group by d.domainenom,passdomaine,d.nic_expires,cli.organisme");
    	return dbconn_dns->fetch_array($i, $query_consult);
    }
    print_r(consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,1))

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    158
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 158
    Par défaut
    ca ne me retourne rien ca me met une erreur !

    Warning: pg_fetch_array() [function.pg-fetch-array]: Unable to jump to row 1 on PostgreSQL result

  9. #9
    Membre éprouvé Avatar de julien.63
    Profil pro
    balayeur
    Inscrit en
    Décembre 2005
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : balayeur

    Informations forums :
    Inscription : Décembre 2005
    Messages : 1 348
    Par défaut
    salut,
    y'a surement une erreur au niveau de ta requête.
    Avec le code ci-dessous tu auras la requête exacte envoyée au serveur postgresql. Essaye de voir ce qui ne vas pas dedans et ensuite corrige la dans ton code.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    function consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,$i)
    {
            $query = "select d.domainenom,cli.organisme,d.passdomaine,d.nic_expires,max(c.daterelance)from domaine_attente da, domainecoord d, client cli , commentaires c where d.idxdomaine = da.idxdomaine and d.asp=6 and d.qualification = 'C' and d.datecreation isnull and dateenregistrement isnull and da.idxattente = 1 and cli.numclient = d.numclient and chargeclientele = 5 and c.idxdomaine = d.idxdomaine group by d.domainenom,passdomaine,d.nic_expires,cli.organisme";
    	$query_consult = $dbconn_dns->query($query);
            echo '<p>'.$query.'</p>';
    	return dbconn_dns->fetch_array($i, $query_consult);
    }
    print_r(consult_nom_attente($dbconn_dns,$asp,$qualif,$id,$dc,$de,$att,1))

Discussions similaires

  1. [Vb.Net] - Function - RETURN
    Par Claude Robin dans le forum Windows Forms
    Réponses: 10
    Dernier message: 29/11/2007, 19h58
  2. [Système] Variable dans echo !
    Par alaindelon dans le forum Langage
    Réponses: 2
    Dernier message: 22/11/2007, 14h36
  3. [Système] Probleme execution echo"<br/>";
    Par sellyh2 dans le forum Langage
    Réponses: 3
    Dernier message: 13/04/2007, 10h56
  4. function return invalid
    Par stela86 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 13/06/2006, 16h26
  5. Réponses: 8
    Dernier message: 01/04/2006, 15h22

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