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 :

Remplir un tableau JS à l'aide de php depuis une bdd


Sujet :

PHP & Base de données

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2015
    Messages : 59
    Points : 19
    Points
    19
    Par défaut Remplir un tableau JS à l'aide de php depuis une bdd
    Bonjour tout le monde!

    Derrière ce titre barbare se cache en fait un problème facile pour certains mais complexe pour moi...
    Pour aller à l'essentiel, je travaille sur un calendrier de réservations, les jours qui composent ce calendrier peuvent avoir 3 états : "free", "pending", "booked" ("libre", "en attente" et "occupé" pour ceux qui seraient fâchés avec l'anglais... :p )
    Ces états sont stockés dans une base de données contenant les infos de la réservation, lorsqu'une location est faite, la page introduit la nouvelle entrée dans la bdd (l'état est directement mis à "pending"), ça, ça fonctionne très bien.

    Le problème survient lorsque je charge la page, je veux faire une lecture de la bdd afin de remplir un tableau qui contient les dates de la bdd et leur état afin de colorer le calendrier selon chaque date, sauf que, ce tableau est un tableau JavaScript (obligatoirement, j'en ai besoin dans mes traitements qui sont, eux aussi, en JS ), j'ai vu qu'on pouvait remplir un tableau JS avec du PHP avec des echo (pas la peine de me rappeler que le JS et PHP ne sont normalement pas compatibles vu qu'un est serveur et l'autre coté client...), mais ça ne marche pas...

    Voici à quoi devraient ressembler le tableau formé par le PHP :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var arrayB = {'2017-08-01':'pending', '2017-08-18':'booked'};
    Pour rappel, ce tableau est un tableau JS...

    Voici comment je l'instancie avec le 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
    <script>
              // array à générer par exemple en php à partir des dates
              //'2017-08-01':'pending'
              var arrayB = new Array(
              <?php
                try
                {
                  $bdd = new PDO('mysql:host=localhost;dbname=asbl;charset=utf8', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
                }
                catch(Exception $e)
                {
                //En cas d'erreur, on affiche un message et on arrête tout
                  die('Erreur : '.$e->getMessage());
                }
                $tab = array();
     
                $reponse = $bdd->query('SELECT dateReserv, etat FROM locations');
     
                $nbLignes = mysql_num_rows($reponse);
     
                for($i = 0; $i <= $nbLignes; $i++)
                {
                  if($i!=0)
                    echo ', ';
                  $donnees = $reponse->fetch();
                  $entree = $donnees['dateReserv'] . ':' . $donnees['etat'];
                  $tab[$i] = $entree;
     
                  echo $tab[$i];
                }
                $reponse->closeCursor();
              ?>
              );
            </script>
    Voici un screenshot de la bdd :

    Nom : bdd.jpg
Affichages : 1372
Taille : 109,3 Ko

    Voici ce que ça devrait donner :

    pour le tableau JS suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    var arrayB = {'2017-08-10':'pending', '2017-08-20':'booked', '2017-08-15':'pending'};
    On obtient ceci :

    Nom : cal.jpg
Affichages : 1394
Taille : 19,4 Ko

    Je pense avoir tout dit, si vous avez d'autres questions, n'hésitez pas!

  2. #2
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Tu mélanges PDO et instructions mysql. Ca ne peut pas marcher.

    Pas testé mais ça devrait ressembler à ça.
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
       $tab = array();
                while($donnees = $reponse->fetch())
                {
                  $entree  = "'".$donnees['dateReserv'] ."' : '". $donnees['etat']."'";
                  $tab[] = $entree;
     
                }
                echo implode(',',$tab);

    Attention dans ta requête SQL tu prends tous les enregistrements indépendamment d'une date de départ.
    De plus tu devrais faire un order by dateReserv pour que les enregistrements soient triés.
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2015
    Messages : 59
    Points : 19
    Points
    19
    Par défaut
    décidément Badaze, on se voit souvent ces temps-ci

    Plus sérieusement, j'ai remplacé mon code par le tien mais ça ne fonctionne toujours pas, voici ce que j'ai :

    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
    <script>
              // array à générer par exemple en php à partir des dates
              //'2017-08-01':'pending'
              var arrayB = new Array(
              <?php
                try
                {
                  $bdd = new PDO('mysql:host=localhost;dbname=asbl;charset=utf8', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
                }
                catch(Exception $e)
                {
                //En cas d'erreur, on affiche un message et on arrête tout
                  die('Erreur : '.$e->getMessage());
                }
     
                $reponse = $bdd->query('SELECT dateReserv, etat FROM locations ORDER BY dateReserv');
     
                $tab = array();
                while($donnees = $reponse->fetch())
                {
                  $entree  = "'".$donnees['dateReserv'] ."' : '". $donnees['etat']."'";
                  $tab[] = $entree;
     
                }
                echo implode(',',$tab);
                $reponse->closeCursor();
              ?>
              );
            </script>
    Je ne sais pas si le ORDER BY sert vraiment à quelque chose mais je l'ai mis pour la forme :p
    Je n'ai pas encore mis la date minimum mais chaque chose en son temps ;D

  4. #4
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Que donne le code généré ? As-tu mis des traces avant le while, dans le while pour voir si ça passe dedans ou pas ?
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2015
    Messages : 59
    Points : 19
    Points
    19
    Par défaut
    J'obtiens un calendrier avec des cases blanches (comme sur l'autre discussion si je ne m'abuse...)

    Ceci :

    Nom : cale.jpg
Affichages : 1298
Taille : 8,8 Ko


    j'ai ajouté des alert() dans le code (en fermant et réouvrant les balises php) et ca ne passe ni avant ni dans le while... donc c'est comme s'il passait l'instanciation du tableau JS...

  6. #6
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Non.

    il faut mettre les traces en php. N'oublie pas que le php est côté serveur.

    Ensuite que donne le source de la page ?
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  7. #7
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2015
    Messages : 59
    Points : 19
    Points
    19
    Par défaut
    Je ne vois aucune trace mais pourtant ça semble fonctionner, voici le source :

    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
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
     
    <!DOCTYPE html>
    <html>
        <head>
          <style type="text/css">
            @import url('https://fonts.googleapis.com/css?family=Open+Sans:600,400');
            #wp-calendar {
              margin: 25px auto 0;
     
              color: hsl(0, 0%, 60%);
              font-family: 'Open Sans', Arial, sans-serif;
              font-size: 12px;
            }
            #wp-calendar caption {
              margin-bottom: 10px;
            }
            thead tr > th,
            tbody tr > td {
              width: 30px;
              height: 30px;
              text-align: center;
            }
            thead tr > th {
              border-left: 1px solid;
              border-right: 1px solid;
              border-color: hsl(0, 0%, 85%);
     
              color: hsl(0, 51%, 53%);
              font-size: 11px;
            }
            thead tr > th:first-child,
            tbody tr > td:first-child {
              border-left: none;
            }
            thead tr > th:last-child,
            tbody tr > td:last-child {
              border-right: none;
            }
            tbody tr:last-child td {
              border-bottom: none;
            }
            tbody tr > td {
              border: 1px solid;
              border-color: hsl(0, 0%, 85%);
            }
            tbody tr > td#today { 
              border-style: solid;
              border-width: medium; 
              border-color: black;
              font-weight: 600;
            }
            tfoot tr > td {
              padding: 5px 0 0 0;
              font-size: 11px;
            }
            tfoot tr > td a {
              color: hsl(0, 0%, 60%);
              text-decoration: none;
            }
            .booked  
            {
              color: hsl(0, 0%, 20%);
              background-color:rgba(255, 0, 0, 0.5);
              font-weight: 600;
            }
            .pending 
            {
              color: hsl(0, 0%, 20%);
              background-color:rgba(255, 191, 0, 0.5);
              font-weight: 600;
            }
            .free { 
              color: hsl(0, 0%, 20%);
              background-color:rgba(0, 255, 0, 0.5);
              font-weight: 600;
            }
            </style>
            <script>
              // array à générer par exemple en php à partir des dates
              //'2017-08-01':'pending'
              var arrayB = new Array(
              '2017-08-15' : 'pending'          );
            </script>
            <meta charset="utf-8" />
            <title>ASBL La Casbah Trasenster</title>
        </head>
     
        <body>
        <!-- Image d'accueil + titre -->
            <div id="bloc_page">
     
                <header>
            <div id="titre_principal">
                <div id="logo">
                    <a href="accueil.php"><img src="images/logo_asbl.png" alt="Logo ASBL" /></a> 
                </div>
             </div>
     
             <div id="header">
                      		<ul>
    	                <li><a href="inscription.php">Inscription</a></li>
    	        		<li><a href="connexion.php">Connexion</a></li>
    	    		</ul>
     
     
            </div>            
    </header>            
                <div id="banniere_image"> 
                <!-- Image bannière -->
                </div>
     
                <h1>Page de location de la salle</h1>
     
     
                <nav>
         <ul>
            <li><a href="accueil.php">Accueil</a></li>
            <li><a href="activites.php">Activités</a></li>
            <li>Réservations</li>
                <ul>
                    <li><a href="location_salle.php">Location salle</a></li>
                    <li><a href="reservation_activites.php">Réservation activités</a></li>
                </ul>
            <li><a href="photos.php">Galerie photos</a></li>
            <li><a href="caritatif.php">Projets caritatifs</a></li>
            <li><a href="partenaires.php">Nos partenaires</a></li>
            <li><a href="connexionMembres.php">Espace membres ASBL</a></li>
            <li><a href="Contacts.php">Contact</a></li>
        </ul>
        <a href="https://www.facebook.com/profile.php?id=100005751197632&amp;fref=ts" title="Facebook" target="_blank"><img src="images/facebook.png" alt="Facebook" /></a>
    </nav>
                <div>
                  <form method="post" action="locationTraitement.php">
                    Nom : 
                    <input type="text" name="nom" />
                    <br/>
                    Prénom :
                    <input type="text" name="prenom" />
                    <br/>
                    Email :
                    <input type="email" name="mail" />
                    <br/>
                    Téléphone :
                    <input type="text" name="telephone" />
                    <br/>
                    Date :
                    <input type="text" name="dateRes" id="dateRes" readonly="true" />
                    <br/>
     
                    <div id="cal">
                      <table id="wp-calendar">
                          <caption>Month Year</caption>
                          <thead>
                          <tr>
                            <th scope="col" title="Lundi">Lu</th>
                            <th scope="col" title="Mardi">Ma</th>
                            <th scope="col" title="Mercredi">Me</th>
                            <th scope="col" title="Jeudi">Je</th>
                            <th scope="col" title="Vendredi">Ve</th>
                            <th scope="col" title="Samedi">Sa</th>
                            <th scope="col" title="Dimanche">Di</th>
                          </tr>
                        </thead>
     
                        <tbody>
                          <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                          </tr>
                          <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                          </tr>
                          <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                          </tr>
                          <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                          </tr>
                          <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                          </tr>
                        </tbody>
     
                        <tfoot>
                          <tr>
                            <td colspan="3" id="prev">
                              <a href="#" title="Mois Précédent"></a>
                            </td>
                            <td colspan="2">&nbsp;</td>
                            <td colspan="3" id="next">
                              <a href="#" title="Mois Suivant"></a>
                              </td>
                          </tr>
                        </tfoot>
                      </table>
                      <script src='//production-assets.codepen.io/assets/common/stopExecutionOnTimeout-b2a7b3fe212eaa732349046d8416e00a9dec26eb7fd347590fbced3ab38af52e.js'></script>
                      <script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
                      <script>
                          var ajd = new Date();
                          var ajdJour = ajd.getDate();
                          var ajdMois = ajd.getMonth();
                          var ajdAnnee = ajd.getFullYear();
                          var jour;
                          var mois;
                          var annee;
     
                          var stringMonth = function(m)
                          {
                            switch(parseInt(m))
                            {
                              case 0:  return 'January';
                              case 1:  return 'February';
                              case 2:  return 'March';
                              case 3:  return 'April';
                              case 4:  return 'May';
                              case 5:  return 'June';
                              case 6:  return 'July';
                              case 7:  return 'August';
                              case 8:  return 'September';
                              case 9:  return 'October';
                              case 10: return 'November';
                              case 11: return 'December';
                              default: return '#ERROR#';
                            }
                          }
     
                          var stringMois = function(month)
                          {
                            switch(month)
                            {
                              case 'January': return 'Janvier';
                              case 'February': return 'Février';
                              case 'March': return 'Mars';
                              case 'April': return 'Avril';
                              case 'May': return 'Mai';
                              case 'June': return 'Juin';
                              case 'July': return 'Juillet';
                              case 'August': return 'Août';
                              case 'September': return 'Septembre';
                              case 'October': return 'Octobre';
                              case 'November': return 'Novembre';
                              case 'December': return 'Décembre';
                            }
                          }
     
                          var setUpCalendar = function(monthToShow)
                          {
                            if (typeof monthToShow == 'string')
                                monthToShow = new Date(monthToShow);
                            if (typeof monthToShow == 'object')
                                monthToShow = monthToShow;
                            else
                                monthToShow = new Date();
     
                            // Vars
                            var m = monthToShow.getMonth();
                            var y = monthToShow.getFullYear();
                            var numDays = new Date(y, m + 1, 0).getDate();
                            var fom = new Date(y, m, 1).getDay();
                            var lom = new Date(y, m + 1, 0).getDay();
                            var current = m == new Date().getMonth() &&
                                          y == new Date().getFullYear();
     
                            var curDate = new Date().toISOString().substr(0,10);
     
                            // Correct for Sundays
                            if (fom == 0)
                              fom = 7;
                            if (lom == 0)
                              lom = 7;
     
                            // Correct the # of rows, say if 6
                            if ((fom == 7 && numDays > 29) || (fom == 6 && numDays == 31))
                              $('<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>').appendTo('tbody');
                            // or only 4 are needed
                            if (fom == 1 && numDays == 28)
                              $('tbody tr:last-child').remove();
     
                            // Set title
                            var month = stringMonth(m);
                            mois = stringMois(month);
                            annee = y;
                            $('table > caption').html(month+' '+y);
     
                            // Add starting space and remove extra cells
                            if (fom != 1) 
                            {
                              $('tbody > tr:first-child > td').eq(0).attr('colspan', fom - 1);
                              $('tbody > tr:first-child').children().slice(9 - fom).remove();
                            }
     
                            // Add ending space and remove extra cells
                            if (lom != 7) 
                            {
                              $('tbody > tr:last-child > td').eq(lom).attr('colspan', 7 - lom);
                              $('tbody > tr:last-child').children().slice(lom + 1).remove();
                            }
     
                            // Add dates in correct cells
                            var $cells = $('tbody td');
                            // If we have spaces, remove them
                            if ($cells.eq(0).attr('colspan'))
                            {
                              $cells = $cells.slice(1);
                            }
                            if ($cells.eq($cells.length-1).attr('colspan'))
                            {
                              $cells = $cells.slice(0, $cells.length-1);
                            }
                            $cells.each(function(i, elem)
                            {
                              var dateSAMJ = annee + '-' + ((m+1).toString().length == 1 ? '0'+(m+1).toString() : (m+1).toString()) + '-' + ((i+1).toString().length == 1 ? '0'+(i+1).toString() : (i+1).toString());
                              if (arrayB[dateSAMJ] != undefined) 
                              {
                                $(elem).attr('class',arrayB[dateSAMJ]);
                              }
                              else 
                              {
                                if (curDate < dateSAMJ) 
                                {
                                  $(elem).attr('class','free'); 
                                }
                              }
     
                              $(elem).html(i+1);
                            });
     
                            $cells.each(function(elem)
                            {
                              if(m <= ajdMois || y <= ajdAnnee)
                              {
                                if(m == ajdMois && y == ajdAnnee)
                                {
                                  if(elem < (ajdJour))
                                  {
                                    $(this).attr('class','booked');
                                  }
                                }
                                if(y < ajdAnnee)
                                {
                                  $(this).attr('class','booked');
                                }
     
                                if(m < ajdMois && y == ajdAnnee)
                                {
                                  $(this).attr('class','booked');
                                }
                              }
                            });
     
                            // Add shading to today's date
                            if(current)
                              $cells.eq(new Date().getDate()-1).attr('id', 'today');
     
                            var prevM = monthToShow.getMonth()-1;
                            if(prevM == -1)
                              prevM = '11';
                            $('#prev a').html('&laquo; '+stringMonth(prevM));
                            var nextM = (monthToShow.getMonth()+1) % 12;
                            $('#next a').html(stringMonth(nextM)+' &raquo;');
                          }
     
                          var resetCalendar = function()
                          {
                            $('tbody').empty();
                            $('tbody').html('<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>');
                          }
     
                          $('#prev a').click(function()
                          {
                            var showing = new Date('01 '+$('table > caption').html());
                            var prevM = showing.getMonth();
                            var prevY = showing.getFullYear();
                            if(prevM == 0){
                              prevM = '12';
                              prevY--;
                            }
                            resetCalendar();
                            setUpCalendar(new Date(prevM+'/01/'+prevY));
                          });
                          $('#next a').click(function()
                          {
                            var showing = new Date('01 '+$('table > caption').html());
                            var nextM = showing.getMonth()+2;
                            var nextY = showing.getFullYear();
                            if(nextM == 13)
                            {
                              nextM = '01';
                              nextY++;
                            }
                            resetCalendar();
                            setUpCalendar(new Date(nextM+'/01/'+nextY));
                          });
     
                          $(document).on("click", ".free", function()
                            {
                              document.getElementById("dateRes").value = this.innerHTML + ' ' + mois + ' ' + annee
                            });
     
                          setUpCalendar();
                      </script>
     
                    </div>
     
                    <input type="submit" name="Valider">
                  </form>
                </div>
     
     
     
                <footer>
        <div id="Contact">
            <h2>Contacts</h2>
                <ul>
                 <li>email : aaa@bbb.com</li>
                 <li>telephone : 0000/00.00.00</li>
                 <li>Adresse : 123A rue AAA 0000 Swagg</li>
                </ul>
        </div>
        <div id="Reseaux_sociaux">
            <h1>Réseaux sociaux</h1>
                <div id="reseaux_sociaux">
                    <p>
                        <a href="https://www.facebook.com/profile.php?id=100005751197632&amp;fref=ts" title="Facebook" target="_blank"><img src="images/facebook.png" alt="Facebook" /></a>
                    </p>
     
                </div>
        </div>
    </footer>            
        	</div>
        </body>
    </html>
    On peut y voir :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    var arrayB = new Array(
              '2017-08-15' : 'pending'          );
    Qui est correct, j'ai effectivement une seule entrée dans ma base de données qui est bien le 15-08-2015 à l'état pending...
    Sauf que l'affichage du calendrier est tout blanc comme sur le message précédent...

  8. #8
    Membre émérite
    Avatar de badaze
    Homme Profil pro
    Chef de projets info
    Inscrit en
    Septembre 2002
    Messages
    1 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Chef de projets info
    Secteur : Transports

    Informations forums :
    Inscription : Septembre 2002
    Messages : 1 412
    Points : 2 522
    Points
    2 522
    Par défaut
    Tu as ...
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    var arrayB = new Array(
              '2017-08-15' : 'pending'          );


    Il faut écrire

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    
    var arrayB = {
              '2017-08-15' : 'pending'          };

    Par rapport à la version d'il y a quelques temps la date du jour n'a pas le fond qui correspond à son état.
    Cela ne sert à rien d'optimiser quelque chose qui ne fonctionne pas.

    Mon site : www.emmella.fr

    Je recherche le manuel de l'Olivetti Logos 80B.

  9. #9
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Décembre 2015
    Messages : 59
    Points : 19
    Points
    19
    Par défaut
    pffff y'a des jours où je me fatigue moi-même... c'est pas tous les jours facile :p

    Ca marche nickel maintenant! Encore merci!

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

Discussions similaires

  1. Remplir un tableau a l'aide d'une boucle
    Par cefyou91 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 17/06/2015, 18h51
  2. Réponses: 6
    Dernier message: 24/06/2014, 15h25
  3. [MySQL] Code PhP pour afficher une BDD
    Par FSDonwload dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 27/04/2008, 00h15
  4. Réponses: 4
    Dernier message: 18/02/2007, 20h28
  5. Aide sur la création d'une bdd sous MySQL
    Par Shellai-93 dans le forum Débuter
    Réponses: 20
    Dernier message: 18/08/2006, 11h15

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