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 :

Bouton checkbox qui exécute des requêtes


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Février 2013
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2013
    Messages : 55
    Points : 27
    Points
    27
    Par défaut Bouton checkbox qui exécute des requêtes
    Bonjour

    Habituellement j'inclus un bouton checkbox qui affiche une nouvelle page suivant le mois sélectionner avec 2 nouvelles requêtes!
    Pour éviter d'avoir 12 pages différentes, on m'a transmis un script pour avoir un bouton checkbox qui exécute des requêtes.
    Mais je ne sais pas trop comment l'adapter

    Code html :
    Code html : 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
    <title>test</title>
    <head>
    <script src="jquery-1.11.0.js" type="text/javascript"></script>
    </head>
    <div id="test">
    </div>
    <table width="100%">
      <tr>
        <td>
      <form name="formulaire3">
        Mois de:
      <select name="mois">
      <option selected="selected">janvier</option>
      <option>fevrier</option>
      <option>mars</option>
      <option>avril</option>
      <option>mai</option>
      <option>juin</option>
      <option>juillet</option>
      <option>aout</option>
      <option>septembre</option>
      <option>octobre</option>
      <option>novembre</option>
      <option>decembre</option>
      </select>
    </form></td>
      </tr>
    </table>
    <br />

    Code :
    Code javascript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    $(function () {
           var choix= this.selectedIndex;
                $.get( "tab.php?choix=1", function( data ) {
                     $('#test').html(data);
                 });
    });
    $( "select" ).change(function () {
       var choix= this.selectedIndex+1;
               $.get( "tab.php?choix="+choix, function( data ) {
                     $('#test').html(data);
               });
    });

    Fichier: tab.php
    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
    <?php
     
     if (isset( $_GET['choix'])) {
    $devis = $_GET['choix'];
    }
     
    // on lance la requête pour récupérer les enregistrements correspondants au numéro de page courante
    $query = "SELECT * FROM devis".$devis." WHERE qte<50 ORDER BY id_devis DESC";
     
    echo $query;exit;
     
    $resultat = mysql_query ($query) or die('pb de connexion ?');
     
    // tant qu'il y a un enregistrement, les instructions dans la boucle s'exécutent
    ?> <h3>- de 50 véhicules</h3> <?php
     
    echo "<table class='full list'>";
      echo "<tr>";
      echo "<th align='center' width='2%'>id</th>";
      echo "<th align='center' width='9%'>Date</th>";
      echo "<th align='center' width='2%'>Qte</th>";
      echo "<th align='center' width='10%'>Type</th>";
      echo "<th align='center' width='10%'>Délai</th>";
      echo "<th align='center' width='10%'>Nom</th>";
      echo "<th align='center' width='10%'>Prénom</th>";
      echo "<th align='center' width='10%'>Fonction</th>";
      echo "<th align='center' width='10%'>Société</th>";
      echo "<th align='center' width='7%'>CP</th>";
      echo "<th align='center' width='10%'>Email</th>";
      echo "<th align='center' width='10%'>Téléphone</th>";
      echo "</tr>";
     
     while ($ligne = mysql_fetch_assoc($resultat)) {
     
      echo "<tr>";
      echo "<td align='center' width=''>".$ligne['id_devis']."</td>";
      echo "<td align='center' width=''>".$ligne['date']."</td>";
      echo "<td align='center' width=''>".$ligne['qte']."</td>";
      echo "<td align='center' width=''>".$ligne['type']."</td>";
      echo "<td align='center' width=''>".$ligne['delai']."</td>";
      echo "<td align='center' width=''>".$ligne['nom']."</td>";
      echo "<td align='center' width=''>".$ligne['prenom']."</td>";
      echo "<td align='center' width=''>".$ligne['fonction']."</td>";
      echo "<td align='center' width=''>".$ligne['societe']."</td>";
      echo "<td align='center' width=''>".$ligne['cp']."</td>";
      echo "<td align='center' width=''>".$ligne['mail']."</td>";
      echo "<td align='center' width=''>".$ligne['tel']."</td>";
      echo "</tr>";
      echo "<tr>";
      echo "<td colspan='12'><span style='font-weight: bold'>Commentaires : </span>".$ligne['contenu']."</td>";
      echo "</tr>";
    }
    echo "</table>";
     
    if(isset($erreur)) echo $erreur;
     
    // on lance la requête pour récupérer les enregistrements correspondants au numéro de page courante
    $query2 = "SELECT * FROM devis".$devis." WHERE qte>50 ORDER BY id_devis DESC";
     
     
    $resultat2 = mysql_query ($query2) or die('pb de connexion ?');
     
    // tant qu'il y a un enregistrement, les instructions dans la boucle s'exécutent
    ?> <h3>+ de 50 véhicules</h3> <?php
     
    echo "<table class='full list'>";
      echo "<tr>";
      echo "<th align='center' width='2%'>id</th>";
      echo "<th align='center' width='9%'>Date</th>";
      echo "<th align='center' width='2%'>Qte</th>";
      echo "<th align='center' width='10%'>Type</th>";
      echo "<th align='center' width='10%'>Délai</th>";
      echo "<th align='center' width='10%'>Nom</th>";
      echo "<th align='center' width='10%'>Prénom</th>";
      echo "<th align='center' width='10%'>Fonction</th>";
      echo "<th align='center' width='10%'>Société</th>";
      echo "<th align='center' width='7%'>CP</th>";
      echo "<th align='center' width='10%'>Email</th>";
      echo "<th align='center' width='10%'>Téléphone</th>";
      echo "</tr>";
     
     while ($ligne2 = mysql_fetch_assoc($resultat2)) {
     
      echo "<tr>";
      echo "<td align='center' width=''>".$ligne2['id_devis']."</td>";
      echo "<td align='center' width=''>".$ligne2['date']."</td>";
      echo "<td align='center' width=''>".$ligne2['qte']."</td>";
      echo "<td align='center' width=''>".$ligne2['type']."</td>";
      echo "<td align='center' width=''>".$ligne2['delai']."</td>";
      echo "<td align='center' width=''>".$ligne2['nom']."</td>";
      echo "<td align='center' width=''>".$ligne2['prenom']."</td>";
      echo "<td align='center' width=''>".$ligne2['fonction']."</td>";
      echo "<td align='center' width=''>".$ligne2['societe']."</td>";
      echo "<td align='center' width=''>".$ligne2['cp']."</td>";
      echo "<td align='center' width=''>".$ligne2['mail']."</td>";
      echo "<td align='center' width=''>".$ligne2['tel']."</td>";
      echo "</tr>";
      echo "<tr>";
      echo "<td colspan='12'><span style='font-weight: bold'>Commentaires : </span>".$ligne2['contenu']."</td>";
      echo "</tr>";
     
    }
    echo "</table>";
     
    if(isset($erreur)) echo $erreur;
    Un petit coup de main SVP.

  2. #2
    Futur Membre du Club
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2014
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    Bonjour,
    pour commencer il me semble qu'il manque une ligne dans ton fichier html :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <script src="./ton_fichier_js.js" type="text/javascript"></script>
    Sinon, pour ce qui est de la pertinence du mécanisme, je me pose la question :
    pourquoi ne pas avoir plutot fait une liste de lien avec en paramètre le choix ?
    Ou alors tout simplement faire un bouton submit pour valider ton formulaire ?

    Ces deux solutions te débarrasserais de tes fonctions js.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2014
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : Service public

    Informations forums :
    Inscription : Janvier 2014
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    Sinon je te propose :

    Code html : 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
    <title>test</title>
    <head>
    <script src="jquery-1.11.0.js" type="text/javascript"></script>
    </head>
    <div id="test">
    </div>
    <table width="100%">
      <tr>
        <td>
      <form name="formulaire3" onchange="submit();" action="tab.php" method="POST">
        Mois de:
      <select name="choix">
      <option selected="selected">veuillez choisir</option>
      <option>janvier</option>  
      <option>fevrier</option>
      <option>mars</option>
      <option>avril</option>
      <option>mai</option>
      <option>juin</option>
      <option>juillet</option>
      <option>aout</option>
      <option>septembre</option>
      <option>octobre</option>
      <option>novembre</option>
      <option>decembre</option>
      </select>
    </form></td>
      </tr>
    </table>
    <br />

    et pour ton fichier tab.php seul le début change :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <?php
     
     if (isset( $_POST['choix'])) {
    $devis = $_POST['choix'];
    }
     
    // on lance la requête pour récupérer les enregistrements correspondants au numéro de page courante
    $query = "SELECT * FROM devis".$devis." WHERE qte<50 ORDER BY id_devis DESC";
     
    echo $query;exit;
     
    $resultat = mysql_query ($query) or die('pb de connexion ?');

Discussions similaires

  1. Bouton checkbox qui exécute des requêtes
    Par vatmx dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 02/02/2014, 13h13
  2. [AC-2010] Bouton qui lance des requêtes SQL
    Par djfox6 dans le forum IHM
    Réponses: 2
    Dernier message: 05/06/2012, 12h13
  3. [requête]Exécution des requêtes
    Par bacchus30 dans le forum Requêtes et SQL.
    Réponses: 1
    Dernier message: 21/05/2007, 12h03
  4. Réponses: 2
    Dernier message: 24/04/2007, 00h18
  5. stats qui affectent des requêtes en mode RULE
    Par joel90 dans le forum Oracle
    Réponses: 4
    Dernier message: 01/02/2005, 14h52

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