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 :

Afficher uniquement lorsque il y a plus d'un enregistrement par id [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre du Club
    Femme Profil pro
    piano
    Inscrit en
    Décembre 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Suisse

    Informations professionnelles :
    Activité : piano
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Décembre 2011
    Messages : 131
    Points : 65
    Points
    65
    Par défaut Afficher uniquement lorsque il y a plus d'un enregistrement par id
    Bonjour,
    Je ne sais pas si mon intitulé est bien explicite!!!
    J'ai un formulaire qui m'affiche tous les enregistrements triés par noms et par date d'arrivée, j'aimerais afficher uniquement les noms qui apparaissent plus d'une fois (c'est-à-dire à partir de deux fois) mais je ne sais pas comment modifier ma requête pour arriver à ce résultat.

    Voici mon formulaire :

    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
     
     
    <?php
    include("menu.php");
    ?>
    <br/>
    <center>
    <?php
    echo '<input type="button" onclick="location.href=\''.( ( $variable == 1 ) ? 'listeloca.php' : 'listeloca.php' ).'\'" value="Recommencer" />';
    ?>
    </center>
    <br />
    <?php		
    function display($string)
    {
        echo htmlentities($string, ENT_QUOTES, 'ISO-8859-1');
    }
     
    include("include/variables.inc.php");
    	$liendb  =  mysql_connect($bddserver,  $bddlogin,  $bddpassword);
    mysql_select_db  ($bdd);
     
    $sql = "SELECT
    	DATE_FORMAT( datearrive, '%d/%m/%Y' ) AS datea,
    	DATE_FORMAT( datearrive, '%Y' ) AS annee,
    	DATE_FORMAT( datedepart, '%d/%m/%Y' ) AS dated,
    	DATEDIFF(datedepart,datearrive ) AS datediff,
    	dateloca.datearrive,
    	dateloca.datedepart,
    	dateloca.nombre,
    	dateloca.prixlocation,
    	dateloca.caution,
    	(dateloca.prixlocation+dateloca.caution+dateloca.linge+dateloca.litbaby) as PT,
            (dateloca.1erpaiement+dateloca.2epaiement+dateloca.3epaiement) as Totalpaye,
            (dateloca.prixlocation+dateloca.caution+dateloca.linge+dateloca.litbaby-dateloca.1erpaiement-dateloca.2epaiement-dateloca.3epaiement) as Reste,
    	(dateloca.1erpaiement+dateloca.2epaiement+dateloca.3epaiement-dateloca.caution) as Totalrevenu,
    	dateloca.1erpaiement,
    	DATE_FORMAT( date1erpaiement, '%d/%m/%Y' ) AS dateunp,
    	dateloca.2epaiement,
    	DATE_FORMAT( date2epaiement, '%d/%m/%Y' ) AS datedeuxp,
    	dateloca.3epaiement,
    	DATE_FORMAT( date3epaiement, '%d/%m/%Y' )	AS datetroisp,
    	dateloca.linge,
    	dateloca.litbaby,
    	dateloca.degatspayes,
    	dateloca.nonpaye,
    	dateloca.remarques,
    	dateloca.restitution,
    	DATE_FORMAT( datelettre, '%d/%m/%Y' ) AS datel,
    	dateloca.appart,
    	dateloca.envoitarifs,
    	dateloca.envoidescriptif,
    	dateloca.paragraphesup,
    	dateloca.confirmation,
    	dateloca.enfants,
    	locataires.nom,
    	locataires.prenom,
    	locataires.idnoms
    		FROM dateloca
    		INNER JOIN locataires ON  dateloca.idnoms = locataires.idnoms
    		WHERE locataires.reserve = 'oui' AND dateloca.annul =2 AND dateloca.prixlocation >0
    		ORDER BY locataires.nom, datearrive desc;";
     
     
    $result = mysql_query($sql);
     
    if($result)
    {
    ?>
        <table border="1">
            <tr>
                <th>id</th>
                <th>Arrivée</th>
                <th>Départ</th>
    	    <th>Nb. jours</th>
    	    <th>Nom et prénom</th>
                <th>Prix Location</th>
                <th>Caution</th>
                <th>Lit bébé</th>
                <th>Linge</th>
                <th>Prix Total</th>																		
    	    <th>Somme payée</th>
                <th>Reste à payer</th>
    	    <th>Degâts payés</th>
    	    <th>Non payé</th>
    	    <th>Revenu</th>
    	    <th>Caution restituée</th>
    	</tr>
    <?php
            while($dateloca = mysql_fetch_assoc($result))
    {
    ?>
                <tr>
                    <td><?php display($dateloca['idnoms']); ?></td>
                    <td><?php display($dateloca['datea']); ?></td>
                    <td><?php display($dateloca['dated']); ?></td>								
                    <td><div class="alindr"><?php display($dateloca['datediff']); ?></div></td>								
                    <td><?php display($dateloca['nom'] . ' - ' .  $dateloca['prenom']); ?></td>
                    <td><div class="alindr"><?php display($dateloca['prixlocation']); ?></div></td>
                    <td><div class="alindr"><?php display($dateloca['caution']); ?></div></td>
                    <td><div class="alindr"><?php display($dateloca['litbaby']); ?></div></td>
                    <td><div class="alindr"><?php display($dateloca['linge']); ?></div></td>																								
                    <td><div class="alindr"><?php display($dateloca['PT']); ?></div></td>
                    <td><div class="alindr"><?php display($dateloca['Totalpaye']); ?></div></td>
                    <td><div class="alindr"><?php display($dateloca['Reste']); ?></div></td>																																								
                    <td><div class="alindr"><?php display($dateloca['degatspayes']); ?></div></td>
                    <td><div class="alindr"><?php display($dateloca['nonpaye']); ?></div></td>
                    <td><div class="alindr"><?php 
    								if ($dateloca['restitution'] == 'non') 0; else
    								display($dateloca['Totalrevenu']); ?></div></td>								
                    <td><div class="alindr"><?php display($dateloca['restitution']); ?></div></td>								
     
    <?php
     
    }
    ?>
     
        </table>
    <br />
    <br />
    <br />
    <br />
    <?php
    }
    mysql_close($liendb);
    ?>
    J'imagine qu'il faut agir sur les "id" mais je ne sais pas comment

    D'avance merci pour votre aide

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2012
    Messages
    631
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2012
    Messages : 631
    Points : 1 220
    Points
    1 220
    Par défaut
    bonjour,
    dans phpmyadmin, tu peux d'abord écrire une petite requête affichant au moins 2 enregistrements:
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     
    "SELECT locataires.idnoms AS id_locataires, COUNT(*) AS total
    		FROM dateloca
    		INNER JOIN locataires ON  dateloca.idnoms = locataires.idnoms
    		WHERE locataires.reserve = 'oui' AND dateloca.annul =2 AND dateloca.prixlocation >0
    		GROUP BY locataires.idnoms
    		HAVING total>=2"
    puis tu considères cette requête comme étant une table ayant pour champs:id_locataires, total.dès lors il ne reste plus qu'à faire une jointure entre cette requête et ta 1ère requête.En voici une implémentation:
    Code php : 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
     
     
    $sql = "SELECT
    	DATE_FORMAT( datearrive, '%d/%m/%Y' ) AS datea,
    	DATE_FORMAT( datearrive, '%Y' ) AS annee,
    	DATE_FORMAT( datedepart, '%d/%m/%Y' ) AS dated,
    	DATEDIFF(datedepart,datearrive ) AS datediff,
    	dateloca.datearrive,
    	dateloca.datedepart,
    	dateloca.nombre,
    	dateloca.prixlocation,
    	dateloca.caution,
    	(dateloca.prixlocation+dateloca.caution+dateloca.linge+dateloca.litbaby) as PT,
            (dateloca.1erpaiement+dateloca.2epaiement+dateloca.3epaiement) as Totalpaye,
            (dateloca.prixlocation+dateloca.caution+dateloca.linge+dateloca.litbaby-dateloca.1erpaiement-dateloca.2epaiement-dateloca.3epaiement) as Reste,
    	(dateloca.1erpaiement+dateloca.2epaiement+dateloca.3epaiement-dateloca.caution) as Totalrevenu,
    	dateloca.1erpaiement,
    	DATE_FORMAT( date1erpaiement, '%d/%m/%Y' ) AS dateunp,
    	dateloca.2epaiement,
    	DATE_FORMAT( date2epaiement, '%d/%m/%Y' ) AS datedeuxp,
    	dateloca.3epaiement,
    	DATE_FORMAT( date3epaiement, '%d/%m/%Y' )	AS datetroisp,
    	dateloca.linge,
    	dateloca.litbaby,
    	dateloca.degatspayes,
    	dateloca.nonpaye,
    	dateloca.remarques,
    	dateloca.restitution,
    	DATE_FORMAT( datelettre, '%d/%m/%Y' ) AS datel,
    	dateloca.appart,
    	dateloca.envoitarifs,
    	dateloca.envoidescriptif,
    	dateloca.paragraphesup,
    	dateloca.confirmation,
    	dateloca.enfants,
    	locataires.nom,
    	locataires.prenom,
    	locataires.idnoms
    		FROM dateloca
    		INNER JOIN locataires ON  dateloca.idnoms = locataires.idnoms
    		JOIN (SELECT locataires.idnoms AS id_locataires, COUNT(*) AS total
    		FROM dateloca
    		INNER JOIN locataires ON  dateloca.idnoms = locataires.idnoms
    		WHERE locataires.reserve = 'oui' AND dateloca.annul =2 AND dateloca.prixlocation >0
    		GROUP BY locataires.idnoms
    		HAVING total>=2) AS req_au_moins_2_locataires
    	        ON locataires.idnoms = req_au_moins_2_locataires. id_locataires
    		ORDER BY locataires.nom, datearrive desc;";

  3. #3
    Membre du Club
    Femme Profil pro
    piano
    Inscrit en
    Décembre 2011
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Suisse

    Informations professionnelles :
    Activité : piano
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Décembre 2011
    Messages : 131
    Points : 65
    Points
    65
    Par défaut
    Merci pour la réponse, ça fonctionne, bonne soirée.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 12/07/2006, 09h51
  2. Réponses: 4
    Dernier message: 05/07/2006, 21h58
  3. [C#/VB.Net]Afficher message lorsque souris survole contrôle
    Par guillaume16 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 20/03/2006, 11h44
  4. Réponses: 7
    Dernier message: 02/03/2006, 12h04
  5. Réponses: 3
    Dernier message: 24/02/2006, 15h11

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