Affichage d'un ensemble de mes tables
logoni
-
imw Messages postés 233 Date d'inscription Statut Membre Dernière intervention -
imw Messages postés 233 Date d'inscription Statut Membre Dernière intervention -
bonjour ,j'ai un code qui ne contient plus de message d'erreur , dans ma requête il m'a permi de faire une jointure, c'est à dire d'accéder à l'information 'libelle' dans la table 'mo'. Mais la valeur de 'code-mo' reste la même. Donc si je veux afficher le libelle, c'est mo.libelle qu'il me faudra utiliser.Et pour cela j'ai besoin de vos aides pour afficher "localisation.libelle","nature.libelle","code.libelle","etat.libelle","date.debut" ,je vous envoie le code entier:
[CODE]<!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."libelle",mo."libelle",nature."libelle",date."date-debut",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 localisation
ON projet."code-localisation" = localisation."code-localisation"
WHERE projet."id-nature" = 1
AND projet."id-date" = 1
AND projet."code-etat"= 1
AND projet."code-localisation" = 1
AND projet."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>/CODE
[CODE]<!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."libelle",mo."libelle",nature."libelle",date."date-debut",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 localisation
ON projet."code-localisation" = localisation."code-localisation"
WHERE projet."id-nature" = 1
AND projet."id-date" = 1
AND projet."code-etat"= 1
AND projet."code-localisation" = 1
AND projet."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>/CODE
A voir également:
- Affichage d'un ensemble de mes tables
- Affichage double ecran - Guide
- Tables des matières word - Guide
- Windows 11 affichage classique - Guide
- Problème affichage page internet google chrome ✓ - Forum Google Chrome
- Tables ascii - Guide
1 réponse
Salut !
A première vue, tu as un soucis dans la méthode de récupération des valeurs :
En fait, en faisant ça, les 3 s'apelle libelle et donc, elles sont écrasée. Il ne faut pas renvoyer plusieurs fois le même nom.
Pour résoudre le problème, tu peut créer des alias :
et dans ton affichage, tu utilise :
Ca te permettra de séparer les valeurs ...
Nico
A première vue, tu as un soucis dans la méthode de récupération des valeurs :
localisation."libelle",mo."libelle",nature."libelle",etat."libelle"
En fait, en faisant ça, les 3 s'apelle libelle et donc, elles sont écrasée. Il ne faut pas renvoyer plusieurs fois le même nom.
Pour résoudre le problème, tu peut créer des alias :
localisation."libelle" as lo-libelle, mo."libelle" as mo-libelle, nature."libelle" as nature-libelle, etat."libelle" as etat-libelle
et dans ton affichage, tu utilise :
$infos['lo-libelle'] $infos['mo-libelle'] $infos['nature-libelle'] $infos['etat-libelle']
Ca te permettra de séparer les valeurs ...
Nico