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 :

Jointures des tables


Sujet :

PHP & Base de données

  1. #1
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 26
    Points : 10
    Points
    10
    Par défaut Jointures des tables
    bjour,je suis débutant en postgresql et en php,après avoir fait des recherches je suis parvenus à faire améliorer mon code php mais je continue à penser qu'il ya des petits erreurs qui sont pas encore corriger ,sans me tromper tout mon problème est au niveau de ma requète SQL et je penses aussi qu'il doit y avoir des modifications dans la partie AFFICHAGE , je comptes sur vous pour m'aidez à le corriger.
    comme vous le voyez j'ai fait une jointure de ma table principale à d'autres tables,et ces autres tables sont liées à ma table principale par des clés étrangères,l'idée c'est de remplacer dans ma table principale ces clés étrangères par leurs libellés correspondantes.aidez moi à obtenir la formule exacte pour cet exercice.
    pour cela vous avez le code suivant



    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
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
             <title> gestion de projet </title>
    		 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     
     
    </head>
    <body>
     
    <?php 
    $conn =("host=localhost port=5432 dbname= gdt user=postgres  password=gabero");
    $dbconn = pg_connect("$conn");
    // connexion à une base de données nommée "gdt" sur l'hôte "localhost" avec un
    // nom d'utilisateur"postgres" et un mot de passe"gabero"  
        	// éxecution de la requète SQL
     
    $sql = pg_query("SELECT projet.id-projet,projet.nom-projet,projet.id-date,projet.id-nature,
    projet.code-localisation,projet.code-etat,projet.code-mo,projet.resultat-projet,projet.montant-projet,
    localisation.libellé,mo.libellé,nature.libellé,date.debut-date,etat.libellé FROM projet INNER JOIN date,projet INNER JOIN etat,projet INNER JOIN nature,projet INNER JOIN mo,projet INNER JOIN localistion 
    	ON projet.code-localisation = localisation.code-localisation
            AND projet.id-date = date.id-date
    		AND projet.code-mo = mo.code-mo
    	    AND projet.id-nature = nature.id-nature
    		AND projet.code-etat = etat.code-etat) ;
    	
    	 where id-nature = 1,id-date =1,code-etat =1,code-localisation =1,code-mo =1 ");
     
    	//En-tete du tableau
    	echo "<table border=\"1\" >
        <caption><strong> PROJET</strong></caption>
       <tr>
           <td>id-projet</td>
    	   <td>nom-projet</td>
    	   <td>code-mo</td>
    	   <td>resultat-projet</td>
    	   <td>montant-projet</td>
    	   <td>code-localisation</td>
    	   <td>id-nature</td>
    	   <td>id-date</td>
    	   <td>code-etat</td>
    	</tr>";
    		// utilisation de la boucle tant que
      while($infos = pg_fetch_array($sql)) {
      // affichage des resultats
      echo"<tr>";//ligne du tableau
      echo "<td>";echo $infos['id-projet'];echo "</td>";
      echo "<td>";echo $infos['nom-projet'];echo "</td>";
      echo "<td>";echo $infos['code-mo'] ;echo "</td>";
      echo "<td>";echo $infos['resultat-projet'] ;echo "</td>";
      echo "<td>";echo $infos['montant-projet'] ;echo "</td>";
      echo "<td>";echo $infos['code-localisation'] ;echo "</td>";
      echo "<td>";echo $infos['id-nature'] ;echo "</td>";
      echo "<td>";echo $infos['id-date'] ;echo "</td>";
      echo "<td>";echo $infos['code-etat'];echo "</td>";
      echo"</tr>"; //fermeture de la ligne
      } //fermeture du tant que
      echo "</table>";//fermeture du tableau 
     
      pg_close($dbconn);
    ?>
    </body>
    </html>
    merci d'avance,ça fait des jours que je tournes en rond

  2. #2
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut
    Bonjour et bienvenu, quand tu mets un code, n'oublie pas de pousser sur le bouton code(#).

    Dans ce que tu propose tu as une erreur de query.
    Pense également à bien séparer ton code PHP de ton code HTML, c'est plus lisible.

    Essaye ceci, et dis nous si cela correspond à ta demande ?

    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
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
        <head>
            <title> gestion de projet </title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     
     
        </head>
        <body>
     
            <?php
            $conn =("host=localhost port=5432 dbname= gdt user=postgres password=gabero");
            $dbconn = pg_connect("$conn");
            // connexion à une base de données nommée "gdt" sur l'hôte "localhost" avec un
            // nom d'utilisateur"postgres" et un mot de passe"gabero"
            // éxecution de la requète SQL
     
            $sql = pg_query("
    SELECT projet.id-projet,projet.nom-projet,projet.id-date,projet.id-nature,
    projet.code-localisation,projet.code-etat,projet.code-mo,projet.resultat-projet,projet.montant-projet,
    localisation.libellé,mo.libellé,nature.libellé,date.debut-date,etat.libellé 
     FROM projet 
        INNER JOIN date
            ON projet.id-date = date.id-date
        INNER JOIN etat
            ON projet.code-etat = etat.code-etat
        INNER JOIN nature
            ON projet.id-nature = nature.id-nature
        INNER JOIN mo
            ON projet.code-mo = mo.code-mo        
        INNER JOIN localistion
            ON projet.code-localisation = localisation.code-localisation
    WHERE id-nature = 1,id-date =1,code-etat =1,code-localisation =1,code-mo =1 ");
            ?>      
            <!-- En-tete du tableau -->
            <table border="1" >
                <caption><strong> PROJET</strong></caption>
                <tr>
                    <td>id-projet</td>
                    <td>nom-projet</td>
                    <td>code-mo</td>
                    <td>resultat-projet</td>
                    <td>montant-projet</td>
                    <td>code-localisation</td>
                    <td>id-nature</td>
                    <td>id-date</td>
                    <td>code-etat</td>
                </tr>
                <?php 
                // utilisation de la boucle tant que
                while($infos = pg_fetch_array($sql)) {
                // affichage des resultats
                echo"<tr>";//ligne du tableau
                    echo "<td>".$infos['id-projet']."</td>";
                    echo "<td>".$infos['nom-projet']."</td>";
                    echo "<td>".$infos['code-mo']."</td>";
                    echo "<td>".$infos['resultat-projet']."</td>";
                    echo "<td>".$infos['montant-projet']."</td>";
                    echo "<td>".$infos['code-localisation']."</td>";
                    echo "<td>".$infos['id-nature']."</td>";
                    echo "<td>".$infos['id-date']."</td>";
                    echo "<td>".$infos['code-etat']."</td>";
                    echo"</tr>"; //fermeture de la ligne
                } //fermeture du tant que
                ?>
                </table> <!--fermeture du tableau-->
     
            <?php pg_close($dbconn); ?>
        </body>
    </html>

  3. #3
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 26
    Points : 10
    Points
    10
    Par défaut problème de jointure des tables
    bjour,merci pour les conseils et je peux dire que cava bcoup mieux mais j'obtiens toujours des messages d'erreur que voici :
    Warning: pg_query() [function.pg-query]: Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe92c6d HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding". in C:\wamp\www\gdt\php.php on line 32
    PROJET id-projet nom-projet code-mo resultat-projet montant-projet code-localisation id-nature id-date code-etat

    Warning: pg_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\gdt\php.php on line 50
    en plus je voudrais injecter un compteur qui permettra d'incrementer les differents identifiants(id-projet,id-nature,id-date,code-localisation,code-mo,code-etat)
    merci d'avance et encore merci tes conseils
    bne journé M.

  4. #4
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut
    Une chose à la fois.

    Je n'avais pas vu , mais dans les nom des tes colonnes tu mets des accents .

    libellé
    Tu ne peux pas, il faut changer cela .

  5. #5
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 26
    Points : 10
    Points
    10
    Par défaut problème de jointure des tables
    d'accord j'ai noté.

  6. #6
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 26
    Points : 10
    Points
    10
    Par défaut problème de jointure des tables
    le message d'erreur que j'obtiens est le suivant:
    Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "," LINE 16: WHERE id-nature = 1,id-date =1,code-etat =1,code-localisatio... ^ in C:\wamp\www\gdt\php.php on line 32
    PROJET id-projet nom-projet code-mo resultat-projet montant-projet code-localisation id-nature id-date code-etat

    Warning: pg_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\gdt\php.php on line 50
    voilà le code après les modifications
    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
     
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
        <head>
            <title> gestion de projet </title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
     
     
        </head>
        <body>
     
            <?php
            $conn =("host=localhost port=5432 dbname= gdt user=postgres password=gabero");
            $dbconn = pg_connect("$conn");
            // connexion à une base de données nommée "gdt" sur l'hôte "localhost" avec un
            // nom d'utilisateur"postgres" et un mot de passe"gabero"
            // éxecution de la requète SQL
     
            $sql = pg_query("
    SELECT projet.id-projet,projet.nom-projet,projet.id-date,projet.id-nature,
    projet.code-localisation,projet.code-etat,projet.code-mo,projet.resultat-projet,projet.montant-projet,
    localisation.libelle,mo.libelle,nature.libelle,date.debut-date,etat.libelle 
     FROM projet 
        INNER JOIN date
            ON projet.id-date = date.id-date
        INNER JOIN etat
            ON projet.code-etat = etat.code-etat
        INNER JOIN nature
            ON projet.id-nature = nature.id-nature
        INNER JOIN mo
            ON projet.code-mo = mo.code-mo        
        INNER JOIN localistion
            ON projet.code-localisation = localisation.code-localisation
    WHERE id-nature = 1,id-date =1,code-etat =1,code-localisation =1,code-mo =1 ");
            ?>      
            <!-- En-tete du tableau -->
            <table border="1" >
                <caption><strong> PROJET</strong></caption>
                <tr>
                    <td>id-projet</td>
                    <td>nom-projet</td>
                    <td>code-mo</td>
                    <td>resultat-projet</td>
                    <td>montant-projet</td>
                    <td>code-localisation</td>
                    <td>id-nature</td>
                    <td>id-date</td>
                    <td>code-etat</td>
                </tr>
                <?php 
                // utilisation de la boucle tant que
                while($infos = pg_fetch_array($sql)) {
                // affichage des resultats
                echo"<tr>";//ligne du tableau
                    echo "<td>".$infos['id-projet']."</td>";
                    echo "<td>".$infos['nom-projet']."</td>";
                    echo "<td>".$infos['code-mo']."</td>";
                    echo "<td>".$infos['resultat-projet']."</td>";
                    echo "<td>".$infos['montant-projet']."</td>";
                    echo "<td>".$infos['code-localisation']."</td>";
                    echo "<td>".$infos['id-nature']."</td>";
                    echo "<td>".$infos['id-date']."</td>";
                    echo "<td>".$infos['code-etat']."</td>";
                    echo"</tr>"; //fermeture de la ligne
                } //fermeture du tant que
                ?>
                </table> <!--fermeture du tableau-->
     
            <?php pg_close($dbconn); ?>
        </body>
    </html>

  7. #7
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut
    Je te l'ai déjà dis, utilise le bouton # pour mettre en valeur ton code, plus facile à lire


    Est-ce que ceci passe correctement? Dans pgadminIII ou PhpPgAdmin ou n'importe quel editeur SQL

    Code SQL : 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
     
    SELECT projet.id-projet,projet.nom-projet,projet.id-date,projet.id-nature,
    projet.code-localisation,projet.code-etat,projet.code-mo,projet.resultat-projet,projet.montant-projet,
    localisation.libelle,mo.libelle,nature.libelle,date.debut-date,etat.libelle
    FROM projet
    INNER JOIN date
    ON projet.id-date = date.id-date
    INNER JOIN etat
    ON projet.code-etat = etat.code-etat
    INNER JOIN nature
    ON projet.id-nature = nature.id-nature
    INNER JOIN mo
    ON projet.code-mo = mo.code-mo
    INNER JOIN localistion
    ON projet.code-localisation = localisation.code-localisation
    WHERE id-nature = 1,id-date =1,code-etat =1,code-localisation =1,code-mo =1

  8. #8
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 26
    Points : 10
    Points
    10
    Par défaut problème de jointure des tables
    non ça passe pas corrrectement c'est pourquoi j'ai envoyé le message d'erreur dans mon message précedent pour que vous m'aidez à corriger ce qui ne va pas dans la partie SELECT et je pense aussi qu'il ya quelque chose qui manque à la partie:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    while($infos = pg_fetch_array($sql)) {
                // affichage des resultats
                echo"<tr>";//ligne du tableau
                    echo "<td>".$infos['id-projet']."</td>";
                    echo "<td>".$infos['nom-projet']."</td>";
                    echo "<td>".$infos['code-mo']."</td>";
                    echo "<td>".$infos['resultat-projet']."</td>";
                    echo "<td>".$infos['montant-projet']."</td>";
                    echo "<td>".$infos['code-localisation']."</td>";
                    echo "<td>".$infos['id-nature']."</td>";
                    echo "<td>".$infos['id-date']."</td>";
                    echo "<td>".$infos['code-etat']."</td>";
                    echo"</tr>"; //fermeture de la ligne
                } //fermeture du tant que

  9. #9
    Modérateur

    Avatar de MaitrePylos
    Homme Profil pro
    DBA
    Inscrit en
    Juin 2005
    Messages
    5 496
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : Belgique

    Informations professionnelles :
    Activité : DBA
    Secteur : Service public

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 496
    Points : 12 596
    Points
    12 596
    Par défaut
    Non, c'est bien dans ton select, mais je suis fatigué et j'ai pas bien vu l'erreur.

    Voici donc le solution de ton query

    Code SQL : 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
     
    SELECT projet.id-projet,projet.nom-projet,projet.id-date,projet.id-nature,
    projet.code-localisation,projet.code-etat,projet.code-mo,projet.resultat-projet,projet.montant-projet,
    localisation.libelle,mo.libelle,nature.libelle,date.debut-date,etat.libelle
    FROM projet
    INNER JOIN date
    ON projet.id-date = date.id-date
    INNER JOIN etat
    ON projet.code-etat = etat.code-etat
    INNER JOIN nature
    ON projet.id-nature = nature.id-nature
    INNER JOIN mo
    ON projet.code-mo = mo.code-mo
    INNER JOIN localistion
    ON projet.code-localisation = localisation.code-localisation
    WHERE id-nature = 1
    AND id-date =1
    AND code-etat =1
    AND code-localisation =1
    AND code-mo =1

    Ton message d'erreur signale un problème de pg_query près de WHERE, effectivement à ce niveau ce sont des AND qui sépare les conditions et non pas des virgules.

  10. #10
    Membre à l'essai
    Inscrit en
    Août 2009
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Août 2009
    Messages : 26
    Points : 10
    Points
    10
    Par défaut problème de jointure des tables
    message reçu et merci de m'avoir consacrer ton temps précieux.
    bne journé et portes toi bien

Discussions similaires

  1. jointure des tables et sortie tmap
    Par rechercheh dans le forum Développement de jobs
    Réponses: 5
    Dernier message: 16/04/2012, 14h14
  2. [Doctrine] jointure des tables de 2 bases de données différentes
    Par kari.mourad dans le forum ORM
    Réponses: 10
    Dernier message: 19/12/2011, 20h09
  3. Requete sql jointure des tables et regroupement
    Par Abed_H dans le forum Requêtes et SQL.
    Réponses: 7
    Dernier message: 22/02/2009, 11h59
  4. Jointure des tables
    Par bhouria dans le forum BIRT
    Réponses: 6
    Dernier message: 29/04/2008, 11h36
  5. Problème jointure des tables
    Par opeo dans le forum SQL
    Réponses: 9
    Dernier message: 28/11/2007, 16h43

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