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 :

Checkbox qui modifie valeur de plusieurs ID


Sujet :

Langage PHP

  1. #21
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2014
    Messages : 36
    Points : 8
    Points
    8
    Par défaut
    les valeurs de ma BDD ne change pas :/

    saisiconvocation.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
    <!DOCTYPE>
    <html>
       <head>
           <title>Association Sportive St Joseph</title>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> 
    	   <link rel="stylesheet" media="screen" type="text/css" href="../style.css" />
    	   <link rel="shortcut icon" type="image/x-icon" href="Images/Icones/unnamed.jpg" />
     
    	</head>
     
    	<body>
    		<?php
    include("../includes/menuad.php");
    ?>
    		<?php
    include("../includes/marquee.php");
    ?>
    		   <div id="corps">
    		<div id='blog'>
    		<form method="get" action="publicationconvo.php">
     
    		<?php
     
    mysql_connect("localhost", "*****", "******");
    mysql_select_db("*******");
     
    // ici on récupère la variable passer en GET
    $classe = $_GET['classe'];
     
    // ici on récupère la variable passer en POST
    $sport   = $_GET['sport'];
    $sexe    = $_GET['sexe'];
     
     
    $hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); };
    $txt = function($p) { return "'".mysql_real_escape_string($p)."'"; };
     
    $sql = <<<sql
    SELECT
        id, nom, prenom, date_de_naissance, sexe, classe, sport, statut, convocation
    FROM
        eleves
    WHERE
        statut     = 0
        AND classe = {$txt($classe)}
        AND sport  = {$txt($sport)}
    sql;
     
    $qry  = mysql_query($sql);
    $rows = array();
     
    if ($qry)
    {
        $i = 0;
        while ($row = mysql_fetch_array($qry))
        {
            ++$i;
            $rows[] = <<<html
    <tr>
        <td>{$i}</td>
        <td>Date</td>
        <td>Lieu</td>
        <td>N°</td>
        <td>{$hsc($row['nom'])}</td>
        <td>{$hsc($row['prenom'])}</td>
        <td>{$hsc($row['classe'])}</td>
        <td><input type="checkbox" name="id[]" value="{$row['id']}"></td>
    </tr>
    html;
        }
    }
     
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Affichage en colonne avec BD - solution 2</title>
    </head>
    <body>
    <form method="POST" action="publicationconvo.php">
        <table id="gestion">
            <thead>
                <tr>
                    <th></th>
                    <th>Date</th>
                    <th>Lieu</th>
                    <th>N°</th>
                    <th>Nom</th>
                    <th>Prénom</th>
                    <th>Classe</th>
                    <th>Sélectionner</th>
                </tr>
            </thead>
            <tbody>
            <?php echo implode('', $rows) ?>
            </tbody>
        </table>
        <br><input name="submit" type="submit" value="Envoyer" />
    </form>
    </html>
    publicationconvo.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
    <?php
    try {
        $bdd = new PDO('mysql:host=localhost;dbname=******', '****', '*****');
    }
    catch (Exception $e) {
        die('Erreur : ' . $e->getMessage());
    }
     
    // Insertion du message à l'aide d'une requête préparée
     
    <?php
     
    if (isset($_POST['submit']) && ( ! empty($_POST['id'])))
    {
        $ids = array_filter(array_map('intval', (array)$_POST['id'])); // on caste toutes les valeurs en int et on élimine celles à zéro
        // construction de la clause WHERE : (id = 1) OR (id = 2) ... OR (id = x)
        $where = array();
        foreach ($ids as $id)
        {
            $where[] = "(id = {$id})";
        }
     
        $sql = 'UPDATE eleves SET convocation = 1 '.((empty($where)) ? '' : 'WHERE '.implode(' OR ', $where));
        $qry = mysql_query($sql);
        echo ($qry) ? 'Convocation effectuée' : 'Aucune modification faite';
    }
    j'ai un doute sur cette ligne aussi

    foreach ($ids as $id)

  2. #22
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    dans publicationconvo.php, pose un var_dump($_POST) et relance le formulaire, coches quelques cases et soumet.
    Poste le résultat.

  3. #23
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2014
    Messages : 36
    Points : 8
    Points
    8
    Par défaut
    rien ne s'affiche ...

  4. #24
    Expert éminent sénior
    Avatar de rawsrc
    Homme Profil pro
    Dev indep
    Inscrit en
    Mars 2004
    Messages
    6 142
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Dev indep

    Informations forums :
    Inscription : Mars 2004
    Messages : 6 142
    Points : 16 545
    Points
    16 545
    Billets dans le blog
    12
    Par défaut
    je me demande si tu comprends bien tout ce que tu fais...
    Il faut vraiment que tu repartes de la base, mais vraiment ^^

    Essaie avec ceci :
    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
    <?php
     
    mysql_connect("localhost", "*****", "******");
    mysql_select_db("*******");
     
    // ici on récupère la variable passer en GET
    $classe = $_GET['classe'];
     
    // ici on récupère la variable passer en POST
    $sport   = $_GET['sport'];
    $sexe    = $_GET['sexe'];
     
     
    $hsc = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); };
    $txt = function($p) { return "'".mysql_real_escape_string($p)."'"; };
     
    $sql = <<<sql
    SELECT
        id, nom, prenom, date_de_naissance, sexe, classe, sport, statut, convocation
    FROM
        eleves
    WHERE
        statut     = 0
        AND classe = {$txt($classe)}
        AND sport  = {$txt($sport)}
    sql;
     
    $qry  = mysql_query($sql);
    $rows = array();
     
    if ($qry)
    {
        $i = 0;
        while ($row = mysql_fetch_array($qry))
        {
            ++$i;
            $rows[] = <<<html
    <tr>
        <td>{$i}</td>
        <td>Date</td>
        <td>Lieu</td>
        <td>N°</td>
        <td>{$hsc($row['nom'])}</td>
        <td>{$hsc($row['prenom'])}</td>
        <td>{$hsc($row['classe'])}</td>
        <td><input type="checkbox" name="id[]" value="{$row['id']}"></td>
    </tr>
    html;
        }
    }
     
    ?>
    <!DOCTYPE>
    <html>
    <head>
       <title>Association Sportive St Joseph</title>
       <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
       <link rel="stylesheet" media="screen" type="text/css" href="../style.css" />
       <link rel="shortcut icon" type="image/x-icon" href="Images/Icones/unnamed.jpg" />
    </head>
    <body>
    <?php
        include '../includes/menuad.php';
        include '../includes/marquee.php';
    ?>
    <div id="corps">
        <div id='blog'>
            <form method="POST" action="publicationconvo.php">
                <table id="gestion">
                    <thead>
                        <tr>
                            <th></th>
                            <th>Date</th>
                            <th>Lieu</th>
                            <th>N°</th>
                            <th>Nom</th>
                            <th>Prénom</th>
                            <th>Classe</th>
                            <th>Sélectionner</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php echo implode('', $rows) ?>
                    </tbody>
                </table>
            <br><input name="submit" type="submit" value="Envoyer" />
            </form>
        </div>
    </div>
    </html>
    Par contre je ne sais pas trop comment tu gères le filtrage : classe, sport, sexe (à toi d'adapter)

  5. #25
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2014
    Messages : 36
    Points : 8
    Points
    8
    Par défaut
    oui je sais ... je regarderai tout a l'heure à tête reposer mais j'ai testé vit fait et ça ne passe pas dans l'URL il va directement sur la page mais je regarderai ce soir tranquillement

  6. #26
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2014
    Messages : 36
    Points : 8
    Points
    8
    Par défaut
    j'ai une question pourquoi as-tu mis du POST et non du GET ?

  7. #27
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    36
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2014
    Messages : 36
    Points : 8
    Points
    8
    Par défaut
    Ouiiiiiiii j'ai reussi

    voilà le code finale

    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
    <!DOCTYPE>
    <html>
       <head>
           <title>Association Sportive St Joseph</title>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> 
    	   <link rel="stylesheet" media="screen" type="text/css" href="../style.css" />
     
    	</head>
     
    	<body>
    		<?php include("../includes/menuad.php"); ?>
    		   <div id="corps">
    		<div id='blog'>
    		<form method="GET" action="publicationconvo.php">
     
    		<?php
     
    mysql_connect("localhost", "Florian", "22051996");
    mysql_select_db("toingma43265com13990_");;
     
    // ici on récupère la variable passer en GET
    $classe = $_GET [ 'classe' ];
     
    // ici on récupère la variable passer en POST
    $sport = $_GET [ 'sport' ];
    $sexe = $_GET [ 'sexe' ];
    $reponse = mysql_query("SELECT id, nom, prenom, date_de_naissance, sexe, classe, sport, statut FROM eleves WHERE statut = 0 AND classe = '".mysql_real_escape_string($classe)."' AND sport = '".mysql_real_escape_string($sport)."' AND sexe = '".mysql_real_escape_string($sexe)."'");
     
     
    $reponse = mysql_query ("UPDATE eleves SET convocation = 0 WHERE sport = '".mysql_real_escape_string($sport)."' AND classe = '".mysql_real_escape_string($classe)."'");    
    $rows    = array();
    $hsc     = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); };
     
     
                 //fin de la boucle, le tableau contient toute la BDD
                mysql_close(); //deconnection de mysql
     
    mysql_connect("localhost", "Florian", "22051996");
    mysql_select_db("toingma43265com13990_");
     
    $reponse = mysql_query("SELECT id, nom, prenom, date_de_naissance, sexe, classe, sport, statut, convocation FROM eleves WHERE statut= 0 AND classe = '".mysql_real_escape_string($classe)."' AND sport = '".mysql_real_escape_string($sport)."'");
    $rows    = array();
    $ligne=0;
    $hsc     = function($p) { return htmlspecialchars($p, ENT_QUOTES, 'utf-8'); };
     
    while($row = mysql_fetch_array($reponse))
    {   
        $rows[] = <<<html
    	
    	
    <tr><center>
        <td>{$hsc(++$ligne)}</td>
        <td>{$hsc($row['nom'])}</td>
        <td>{$hsc($row['prenom'])}</td>
        <td>{$hsc($row['classe'])}</td>
    	<td><center><input type="checkbox" name="id[]" value={$row['id']}></td>
        
    	
        
    html;
     
     
     
    ?>
     
    	 <?php 
                 //fin de la boucle, le tableau contient toute la BDD
               } mysql_close(); //deconnection de mysql
                ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Affichage en colonne avec BD - solution 2</title>
    </head>
    <body>
     
    <center>
    <table id="gestion">
        <thead>
            <tr> 
     
     
    			 <tr>
    			<th>Date</th>
    			<td style='background-color:#a0ffdf'><input type="text" name="date" id="date" style='background-color:#a0ffdf'/></td>
    			<th>Lieu</th>
    			<td style='background-color:#a0ffdf'><input type="text" name="lieu" id="lieu" style='background-color:#a0ffdf' /></td></td>
    			</tr>
                <th>N°</th>
                <th>Nom</th>
                <th>Prenom</th>
    		    <th>Classe</th>
    			<th>Sélectionner</th>
     
     
            </tr>
        </thead>
        <tbody>
     
            <?php echo implode('', $rows); ?>
        </tbody>
    </table>
       <br><input method="get" name="submit" type="submit" value="Envoyer" />  
    </form>
     
     
     
     
     
     
     
     
     
     
     
    </body>
     
                       </div>
     
    		   <div id="footer">
                         <a> Dupuis & Rochet Copyright - Tous droits réservés 2014-2015 </a>
                       </div>
    		</div>
    	</body>
    </html>
    et

    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
    <?php
    try {
        $bdd = new PDO('mysql:host=localhost;dbname=toingma43265com13990_', 'Florian', '22051996');
    }
    catch (Exception $e) {
        die('Erreur : ' . $e->getMessage());
    }
     
    // Insertion du message à l'aide d'une requête préparée
     
    if (isset($_GET['submit']))
    {
    if ( ! empty($_GET['id']))
        {
    	foreach ((array)$_GET['id'] as $id)
            {
        var_dump($id);
        $req = $bdd->prepare('UPDATE eleves SET convocation = 1 WHERE id = :id');
        $req->execute(array(
            ':id' => $id
        ));
    }
    }
    };
     
    ?>
    merci pour ta patiente, il faut que je me remette au cours tout de même.

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. Modifier valeur de plusieurs variables référencées en macro
    Par giallorossi dans le forum Développement
    Réponses: 7
    Dernier message: 30/08/2013, 11h34
  2. Liste deroulante qui modifie les valeurs de plusieur autres listes
    Par luan220 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 10/08/2008, 19h06
  3. Réponses: 2
    Dernier message: 24/08/2007, 14h25
  4. Réponses: 2
    Dernier message: 10/06/2007, 19h41
  5. fonction qui modifie les valeurs de combos <select>
    Par NicoO_O dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 16/05/2007, 13h02

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