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 :

javascript et mysql


Sujet :

JavaScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    salarié
    Inscrit en
    Mars 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : salarié
    Secteur : Alimentation

    Informations forums :
    Inscription : Mars 2011
    Messages : 55
    Par défaut javascript et mysql
    Désole en me relisant j'ai vu que j'avais fait une faute entre Java et Javascript.

    Donc voila j'ai un script qui calcul 3 input pour afficher le resultat dans un autre input :

    Voici mon script :

    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
     <script language="JavaScript"> 
    <!-- 
    function recalculer() 
    { 
    //déclarons trois variables temporaires 
    var val1=0; 
    var val2=0; 
    var val3=0; 
    var val4=0; 
    var val5=0; 
    var val6=0; 
    // et une variable pour le total 
    var total1=val1+val2+val3+val4; 
    var total2=val1+val2+val3; 
    var total3=val5-val6; 
    //pour les menus, le test n'est pas nécessaire 
    val1=parseInt(document.getElementById('g').value); 
    val2=parseInt(document.getElementById('n').value); 
    val3=parseInt(document.getElementById('p').value); 
    val4=parseInt(document.getElementById('f').value); 
    val5=parseInt(document.getElementById('bc').value); 
    val6=parseInt(document.getElementById('bp').value); 
    //calculons le total 
    total1=val1+val2+val3+val4; 
    total2<ital>=(val1*4)+val2*2+val3; 
    total3=val5-val6; 
    //plaçons-le dans le chmaps resultat 
    document.getElementById('resultat1').value=total1;  
    document.getElementById('resultat2').value=total2;  
    document.getElementById('resultat3').value=total3;  
    //le tour est joué    
    } 
    </script>

    Ensuite voila mon code html avec lequel j'affiche les enregistrements de ma base de donnée.

    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
     <table </ital>id="table" cellpadding="0" cellspacing="0" class="tabl_view sortable-onload-3 no-arrow rowstyle-alt colstyle-alt paginate-13 max-pages-7 paginationcallback-callbackTest-calculateTotalRating paginationcallback-callbackTest-displayTextInfo sortcompletecallback-callbackTest-calculateTotalRating"> 
        <thead> 
                <tr> 
                    <th class="t_edit">Modifier</th> 
                    <th class="t_del">Suppr</th> 
                    <th class="numid sortable-num">Place</th> 
     
                    <th class="Clubs">Clubs</th> 
                                    <th class="points">Points</th> 
                                                    <th class="points">Joués</th> 
                    <th class="points">Gagné</th> 
                    <th class="points">Perdu</th> 
                    <th class="points">Nul</th> 
                     <th class="points">Forfait</th> 
                    <th class="points">BC</th> 
                    <th class="points">BP</th> 
                    <th class="points">Dif.</th> 
                    <th class="points">Pen.</th> 
     
                </tr> 
        </thead> 
            <tbody><tr> 
                    <td align="left" nowrap="nowrap" class="c_mod"><a href="index.php?page=classement&modif=<?php echo $match['clas_id']; ?>" title="Modifier"><img src="images/editer.png" /></a></td> 
                <td align="left" nowrap="nowrap" class="c_del"><a href="index.php?page=list-classement&suppr=<?php echo $match['clas_id']; ?>" title="Supprimer" onclick="return(confirm('Etes-vous sûr de vouloir supprimer cette entrée?'));"><img src="images/corbeille.gif" /></a></td> 
                 <td align="left" nowrap="nowrap" class="t_num"><?php echo $num_ligne++; ?></td> 
           <td align="left" nowrap="nowrap"><?php echo $match['clas_club']; ?></td> 
        <td align="left" nowrap="nowrap"><input name="pts[<?php echo $match['clas_id']; ?>]"  id="resultat2" onchange='affich()' value="<?php echo $match['clas_pts'];?>" size="4" style="vertical-align:middle"/></td> 
                            <td align="left" nowrap="nowrap"><input class="clas" name="jo[<?php echo $match['clas_id']; ?>]" id="resultat1" onchange='affich()'value="<?php echo $match['clas_jo']; ?>" size="4" /></td> 
                    <td align="left" nowrap="nowrap"><input class="clas" name="g[<?php echo $match['clas_id']; ?>]" type="text"  id="g" onchange="recalculer();" value="<?php echo $match['clas_g']; ?>" size="4"></td> 
                    <td align="left" nowrap="nowrap"><input class="clas" name="n[<?php echo $match['clas_id']; ?>]" type="text"  id="n" onchange="recalculer();" value="<?php echo $match['clas_n']; ?>" size="4"></td> 
                    <td align="left" nowrap="nowrap"><input  class="clas"name="p[<?php echo $match['clas_id']; ?>]" type="text"  id="p" onchange="recalculer();" value="<?php echo $match['clas_p']; ?>" size="4"></td> 
                           <td align="left" nowrap="nowrap"><input class="clas" name="f[<?php echo $match['clas_id']; ?>]" type="text"  id="f" onchange="recalculer();" value="<?php echo $match['clas_f']; ?>" size="4"></td> 
                    <td align="left" nowrap="nowrap"><input class="clas" name="bc[<?php echo $match['clas_id']; ?>]" id="bc" type="text" onchange="recalculer();" value="<?php echo $match['clas_bc']; ?>" size="4"/></td> 
                    <td align="left" nowrap="nowrap"><input class="clas" name="bp[<?php echo $match['clas_id']; ?>]" id="bp" type="text" onchange="recalculer();" value="<?php echo $match['clas_bp']; ?>" size="4"/></td> 
                    <td align="left" nowrap="nowrap"><input class="clas" name="dif[<?php echo $match['clas_id']; ?>]"  id="resultat3" onchange='affich()' value="<?php echo $match['clas_dif'];?>" size="4" style="vertical-align:middle"/></td> 
                    <td align="left" nowrap="nowrap"><input class="clas" name="pen[<?php echo $match['clas_id']; ?>]" type="text" value="<?php echo $match['clas_pen']; ?>" size="4"/></td> 
     
              </tr> 
    <?php endwhile; ?> 
            </tbody> 
          </table > 
    </code>
    Donc mon problème j'arrive a afficher mon calcul sur la première ligne de ma liste d'enregistrement mais les autres ne font pas le calcul.

    Merci d'avance

  2. #2
    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 659
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    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 659
    Billets dans le blog
    1
    Par défaut
    un id DOIT être unique sur une page ...
    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 !

  3. #3
    Membre actif
    Homme Profil pro
    salarié
    Inscrit en
    Mars 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : salarié
    Secteur : Alimentation

    Informations forums :
    Inscription : Mars 2011
    Messages : 55
    Par défaut
    c'est à dire, d'ou viendrais mon erreur ?

  4. #4
    Expert confirmé
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Par défaut
    j'ai rien pané
    c'est quoi le rapport avec mysql ?
    et c'est sensé faire quoi ?

  5. #5
    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 659
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    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 659
    Billets dans le blog
    1
    Par défaut
    d'après ce que je comprends de ton code tu boucle sen php pour rédiger du code html ...

    Or il me semble bein que dans la boucle tu mets des id fixes ...
    si tu regarde ton code html généré tu dois te retrouver avec plusieurs éléments portant le même id, non ?
    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 !

  6. #6
    Membre actif
    Homme Profil pro
    salarié
    Inscrit en
    Mars 2011
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : salarié
    Secteur : Alimentation

    Informations forums :
    Inscription : Mars 2011
    Messages : 55
    Par défaut
    Voila tous mon code de la page :
    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
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    <?php
       if(isset($_GET['suppr']) && is_numeric($_GET['suppr']))
       {
          supprimerclassement($_GET['suppr']);
       }
     
    ?>
    <h1>Liste des Classements</h1>
     
    <div id="manage_tool">
        <a href="index.php?page=classement" title="Ajouter un Match">
            <img src="images/ajouter_data.png" />
            <span>Ajouter</span>
        </a>
     
    </div>
    <?php
     
        affiche_msg_alert('ajout', 'classement');
        
        affiche_msg_alert('conf', 'classement');
    ?>
    <div id="conteneur_tableau" style="text-align:center">
    <form name="match" action="<?php echo _ADMIN_URL.'index.php?page=list-classement'; ?>" id="ajout_dat" method="post">
     <fieldset>
     
      <legend>Saison :
                <select name="saison" onChange="document.match.compet_id.value='';document.match.submit()">
                <?php $result = get_list_classement(); ?>
                <option value="">Tous</option>
     
                <?php while($compete = mysql_fetch_assoc($result)): ?>
                	<?php if (isset($_POST['saison']) && ($compete['clas_saison']==$_POST['saison'])) {$checked='selected';} else {$checked='';}?>
                    <option value="<?php echo $compete['clas_saison'];?>" <?php echo $checked;?>><?php echo $compete['clas_saison'];?> / <?php echo $compete['clas_saison']+1;?></option>
                <?php endwhile; ?>
                </select>
                Championnat :
                <select name="compet_id" onChange="document.match.submit()">
                <?php 
                	if(isset($_POST['saison']) && ($_POST['saison']!='')) $result = get_list_championnat($_POST['saison']); else 
                	{
                		$_POST['compet_id']='';
                		$result = get_list_compete();
                	}
                ?>
                  <option value="">Toutes compétitions</option>
                <?php while($compete = mysql_fetch_assoc($result)): ?>
                	<?php if (isset($_POST['compet_id']) && ($compete['compet_id']==$_POST['compet_id'])) {$checked='selected';} else {$checked='';}?>
                    <option value="<?php echo $compete['compet_id'];?>" <?php echo $checked?>><?php echo $compete['compet_longname']; ?></option>
                <?php endwhile; ?>
          </select>
          </legend>
      <p>&nbsp;</p>
     
     <input type="hidden" name="edition" value="<?php echo (isset($_GET['modif'])) ? $_GET['modif'] : null; ?>" />
      <table id="table" cellpadding="0" cellspacing="0" class="tabl_view sortable-onload-3 no-arrow rowstyle-alt colstyle-alt paginate-13 max-pages-7 paginationcallback-callbackTest-calculateTotalRating paginationcallback-callbackTest-displayTextInfo sortcompletecallback-callbackTest-calculateTotalRating">
        <thead>
                <tr>
                    <th class="t_edit">Modifier</th>
                    <th class="t_del">Suppr</th>
                    <th class="numid sortable-num">Place</th>
     
                    <th class="Clubs">Clubs</th>
                                    <th class="points">Points</th>
                                                    <th class="points">Joués</th>
                    <th class="points">Gagné</th>
                    <th class="points">Perdu</th>
                    <th class="points">Nul</th>
                     <th class="points">Forfait</th>
                    <th class="points">BC</th>
                    <th class="points">BP</th>
                    <th class="points">Dif.</th>
                    <th class="points">Pen.</th>
     
                </tr>
        </thead>
            <tbody>
    <?php
        if (isset($_POST['saison']) && ($_POST['compet_id']!='')) {
        	$result = get_classement($_POST['saison'],$_POST['compet_id']);
        } else {
        }
        $num_ligne = 1;     // initialisation du numero de chaque champs
        while($match = mysql_fetch_assoc($result) ):
    ?>  <script language="JavaScript">
    <!--
    function recalculer()
    {
    //déclarons trois variables temporaires
    var val1=0;
    var val2=0;
    var val3=0;
    var val4=0;
    var val5=0;
    var val6=0;
    // et une variable pour le total
    var total1=val1+val2+val3+val4;
    var total2=val1+val2+val3;
    var total3=val5-val6;
    //pour les menus, le test n'est pas nécessaire
    val1=parseInt(document.getElementById('g').value);
    val2=parseInt(document.getElementById('n').value);
    val3=parseInt(document.getElementById('p').value);
    val4=parseInt(document.getElementById('f').value);
    val5=parseInt(document.getElementById('bc').value);
    val6=parseInt(document.getElementById('bp').value);
    //calculons le total
    total1=val1+val2+val3+val4;
    total2=(val1*4)+val2*2+val3;
    total3=val5-val6;
    //plaçons-le dans le chmaps resultat
    document.getElementById('resultat1').value=total1; 
    document.getElementById('resultat2').value=total2; 
    document.getElementById('resultat3').value=total3; 
    //le tour est joué   
    }
    </script>
                <tr>
                    <td align="left" nowrap="nowrap" class="c_mod"><a href="index.php?page=classement&modif=<?php echo $match['clas_id']; ?>" title="Modifier"><img src="images/editer.png" /></a></td>
                <td align="left" nowrap="nowrap" class="c_del"><a href="index.php?page=list-classement&suppr=<?php echo $match['clas_id']; ?>" title="Supprimer" onclick="return(confirm('Etes-vous sûr de vouloir supprimer cette entrée?'));"><img src="images/corbeille.gif" /></a></td>
                 <td align="left" nowrap="nowrap" class="t_num"><?php echo $num_ligne++; ?></td>
           <td align="left" nowrap="nowrap"><?php echo $match['clas_club']; ?></td>
        <td align="left" nowrap="nowrap"><input name="pts[<?php echo $match['clas_id']; ?>]"  id="resultat2" onchange='affich()' value="<?php echo $match['clas_pts'];?>" size="4" style="vertical-align:middle"/></td>
                            <td align="left" nowrap="nowrap"><input class="clas" name="jo[<?php echo $match['clas_id']; ?>]" id="resultat1" onchange='affich()'value="<?php echo $match['clas_jo']; ?>" size="4" /></td>
                    <td align="left" nowrap="nowrap"><input class="clas" name="g[<?php echo $match['clas_id']; ?>]" type="text"  id="g" onchange="recalculer();" value="<?php echo $match['clas_g']; ?>" size="4"></td>
                    <td align="left" nowrap="nowrap"><input class="clas" name="n[<?php echo $match['clas_id']; ?>]" type="text"  id="n" onchange="recalculer();" value="<?php echo $match['clas_n']; ?>" size="4"></td>
                    <td align="left" nowrap="nowrap"><input  class="clas"name="p[<?php echo $match['clas_id']; ?>]" type="text"  id="p" onchange="recalculer();" value="<?php echo $match['clas_p']; ?>" size="4"></td>
                           <td align="left" nowrap="nowrap"><input class="clas" name="f[<?php echo $match['clas_id']; ?>]" type="text"  id="f" onchange="recalculer();" value="<?php echo $match['clas_f']; ?>" size="4"></td>
                    <td align="left" nowrap="nowrap"><input class="clas" name="bc[<?php echo $match['clas_id']; ?>]" id="bc" type="text" onchange="recalculer();" value="<?php echo $match['clas_bc']; ?>" size="4"/></td>
                    <td align="left" nowrap="nowrap"><input class="clas" name="bp[<?php echo $match['clas_id']; ?>]" id="bp" type="text" onchange="recalculer();" value="<?php echo $match['clas_bp']; ?>" size="4"/></td>
                    <td align="left" nowrap="nowrap"><input class="clas" name="dif[<?php echo $match['clas_id']; ?>]"  id="resultat3" onchange='affich()' value="<?php echo $match['clas_dif'];?>" size="4" style="vertical-align:middle"/></td>
                    <td align="left" nowrap="nowrap"><input class="clas" name="pen[<?php echo $match['clas_id']; ?>]" type="text" value="<?php echo $match['clas_pen']; ?>" size="4"/></td>
     
              </tr>
    <?php endwhile; ?>
            </tbody>
          </table >
      <p> 
      	<?php
        if (isset($_POST['saison']) && ($_POST['compet_id']!='')) {
        	$result = get_classement($_POST['saison'],$_POST['compet_id']);
        } else {
        	?><center><p>
    	<h1><strong>Veuillez sélectionner une Saison / Compétition</strong></h1></center></p><?php
        }
        $num_ligne = 1;     // initialisation du numero de chaque champs
     
    ?> 
     </fieldset><input type="submit" name="envoyer" value="valider" />
     
     
     </form>
      </p>
     
     
     
    </div>
    Mon script permet d'effectuer le calcul de 3 input " G ; N ; p " Pour afficher le resultat en jo.

  7. #7
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Citation Envoyé par SpaceFrog Voir le message
    d'après ce que je comprends de ton code tu boucle sen php pour rédiger du code html ...

    Or il me semble bein que dans la boucle tu mets des id fixes ...
    si tu regarde ton code html généré tu dois te retrouver avec plusieurs éléments portant le même id, non ?
    Vérifie et montre nous le code html généré mais pas le PHP.

    A+.

  8. #8
    Rédacteur

    Avatar de Bovino
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2008
    Messages
    23 647
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2008
    Messages : 23 647
    Billets dans le blog
    20
    Par défaut
    C'est même pire...
    Non seulement les lignes du tableau sont générées dans une boucle while (donc plusieurs id identiques sont générés), mais il semble aussi que le script JavaScript soit lui aussi créé à chaque itération...
    Pas de question technique par MP !
    Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
    Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
    Mon livre sur jQuery
    Module Firefox / Chrome d'intégration de JSFiddle et CodePen sur le forum

Discussions similaires

  1. Insérer une Variable javascript dans MySQL
    Par MacUser dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 04/08/2008, 18h09
  2. javascript et mysql!
    Par mitnick2006 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 26/05/2008, 09h37
  3. javascript et mysql
    Par schuller dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 09/08/2007, 16h55
  4. [JQuery] Javascript et MySQL
    Par Badaboumpanpan dans le forum jQuery
    Réponses: 12
    Dernier message: 23/06/2007, 10h10
  5. [Débutant] radio button et BDD (javascript/PHP/MySQL)
    Par stringman62 dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 12/02/2007, 19h03

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