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

JavaScript Discussion :

Bouton checkbox qui exécute des requêtes


Sujet :

JavaScript

  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
    Bonsoir

    Voici le code de l'affichage de mes tableaux
    -le premier pour les résultats de - de 50 véhicules
    -le second pour les résultats de + de 50 véhicules
    j'ai donc 2 requêtes ($query et $query2)

    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
    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
    <?php
     
    // on lance la requête pour récupérer les enregistrements correspondants au numéro de page courante
    $query = "SELECT * FROM devis3 WHERE qte<50 ORDER BY id_devis DESC";
     
     
    $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 devis3 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;
    ?>

    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, j'aimerais savoir comment lancer les requêtes directement lors de la sélection du mois en restant sur la même page . Donc avoir un bouton checkbox qui exécute des requêtes
    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
    <script>
    function diri3(){
    var choix=document.formulaire3.mois.selectedIndex
    switch (choix)
    {
    default:location.href="http://www.monsite/tableaux-file-devis_01.html";break;
    case 0:location.href="http://www.monsite/tableaux-file-devis_01.html";break;
    case 1:location.href="http://www.monsite/tableaux-file-devis_02.html";break;
    case 2:location.href="http://www.monsite/tableaux-file-devis_03.html";break;
    case 3:location.href="http://www.monsite/tableaux-file-devis_04.html";break;
    case 4:location.href="http://www.monsite/tableaux-file-devis_05.html";break;
    case 5:location.href="http://www.monsite/tableaux-file-devis_06.html";break;
    case 6:location.href="http://www.monsite/tableaux-file-devis_07.html";break;
    case 7:location.href="http://www.monsite/tableaux-file-devis_08.html";break;
    case 8:location.href="http://www.monsite/tableaux-file-devis_09.html";break;
    case 9:location.href="http://www.monsite/tableaux-file-devis_10.html";break;
    case 10:location.href="http://www.monsite/tableaux-file-devis_11.html";break;
    case 11:location.href="http://www.monsite/tableaux-file-devis_12.html";break;
    }
    }
    </script>
    <table width="100%">
      <tr>
        <td>
      <form name="formulaire3">
        Mois de:
      <select name="mois" onchange="diri3()">
      <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 />
    Merci d'avance pour le coup de main.

  2. #2
    Invité
    Invité(e)
    Par défaut
    j'aimerais savoir comment lancer les requêtes directement lors de la sélection du mois en restant sur la même page
    AJAX ?

  3. #3
    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
    Bonjour

    Alax, je ne connais pas
    Je pensais a une fonction php, ou autre.

    Merci

  4. #4
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 640
    Points : 66 669
    Points
    66 669
    Billets dans le blog
    1
    Par défaut
    Une fonction php ???
    tu es conscient que les actions sur les checkboxes s'effectuent coté client et que ton navigateur n'a jamais entendu parle de php ... il 'interprète que le html css js.
    => qui dit requete dit obligatoirement retour sur le serveur
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    501
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 501
    Points : 102
    Points
    102
    Par défaut proposition
    Salut, je te propose ca

    Fichier: test.html // tu peut changer le nom

    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 : 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 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
    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;
    A toi d'adapter pour tes tableaux

  6. #6
    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
    Bonjour

    Merci pour le code.
    Je vais voir avec l'aide php pour l'adaptation, car je ne vois pas comment faire

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    501
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 501
    Points : 102
    Points
    102
    Par défaut
    Non, tu n'as plus rien à faire l'ami, la table du FROM de ta requête sera variable selon le select de ta checkbox.

    Exemple:
    $query = "SELECT * FROM devis1"[/COLOR] WHERE qte<50 ORDER BY id_devis DESC";

    $query = "SELECT * FROM devis".$devis."WHERE qte<50 ORDER BY id_devis DESC";

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

Discussions similaires

  1. Bouton checkbox qui exécute des requêtes
    Par vatmx dans le forum Langage
    Réponses: 2
    Dernier message: 02/02/2014, 12h30
  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