PHP|Débutant :: Forums

Advertisement

Besoin d'aide ? N'hésitez pas, mais respectez les règles

Vous n'êtes pas identifié(e).

#1 13-12-2015 23:39:41

erwann
Membre
Inscription : 13-12-2015
Messages : 3

Demande d'aide pour mise en oeuvre d'une date dans un <select ... />

Bonjour,

je suis actuellement en train d'essayer de créer un formulaire et d'utiliser un <select/> ou l'on pourrait sélectionner une date. La particularité de ce <select/> serait d'avoir en premier choix la date du jour, avec l'incrémentation de la date sur les autres choix, puis de pouvoir transférer la date choisie vers la base de donnée.

le problème rencontré est que je n'arrive pas à transférer la date complète vers la base de donnée. Cela étant j'arrive à afficher les dates comme voulu dans la liste de choix.

voici mon code :

<tr><td><label for="date rdv">Date RDV </label> :

<select name="date" tabindex="30" />
<option value=<?php setlocale(LC_TIME, 'fra_fra'); $today=date("Y-m-d"); $nextday=strftime("%A %d %B %Y", strtotime("$today +0 day")); echo $nextday?> title=<?php echo $nextday ?><?php echo $nextday?> </option>
<option value=<?php setlocale(LC_TIME, 'fra_fra'); $today=date("Y-m-d"); $nextday=strftime("%A %d %B %Y", strtotime("$today +1 day")); echo $nextday?> title=<?php echo $nextday ?><?php echo $nextday?> </option>
<option value=<?php setlocale(LC_TIME, 'fra_fra'); $today=date("Y-m-d"); $nextday=strftime("%A %d %B %Y", strtotime("$today +2 day")); echo $nextday?> title=<?php echo $nextday ?><?php echo $nextday?> </option>

</select>
</td></tr>

 

Ce bout de code, même fonctionnant partiellement, me semble un peu "barbare", et me convient pas vraiment.. Voila pourquoi je poste ce message afin d'avoir des conseils et remarques qui me permettraient d'arriver à mon objectif.
En vous remerciant. Erwann.

Hors ligne

#2 14-12-2015 00:36:03

tof73
Membre
Inscription : 21-12-2014
Messages : 156
Site Web

Re : Demande d'aide pour mise en oeuvre d'une date dans un <select ... />

dans le value, il faut mettre la date au format dans laquelle elle sera sauvé (Y-m-d si c'est un champ date de mysql) et non dans un format français. ailleurs, le format français ne pose pas de problèmes.

il faut afficher plus d'entrées que J+2 ? si non, alors le code fait le nécessaire.

Hors ligne

#3 14-12-2015 12:19:59

erwann
Membre
Inscription : 13-12-2015
Messages : 3

Re : Demande d'aide pour mise en oeuvre d'une date dans un <select ... />

Merci beaucoup, je vais essayer ce soir.

Hors ligne

#4 14-12-2015 21:12:22

erwann
Membre
Inscription : 13-12-2015
Messages : 3

Re : Demande d'aide pour mise en oeuvre d'une date dans un <select ... />

Bon, du coup j'ai essayé et ça MARCHE !!! trop cool, voici la correction pour ceux que cela interesse, aprés c'est un peu lourd....

<tr><td><label for="date rdv">Date RDV </label> :

<select name="date" tabindex="30" />
<option value=<?php $today=date("Y-m-d"); $nextday=date("Y-m-d", strtotime("$today +0 day")); echo $nextday?> title=<?php echo $nextday ?>>     <?php setlocale(LC_TIME, 'fra_fra'); $formatday=strftime("%A %d %B %Y", strtotime("$today +0 day")); echo $formatday?>  </option>

<option value=<?php $today=date("Y-m-d"); $nextday=date("Y-m-d", strtotime("$today +1 day")); echo $nextday?> title=<?php echo $nextday ?>>     <?php setlocale(LC_TIME, 'fra_fra'); $formatday=strftime("%A %d %B %Y", strtotime("$today +1 day")); echo $formatday?>  </option>

<option value=<?php $today=date("Y-m-d"); $nextday=date("Y-m-d", strtotime("$today +2 day")); echo $nextday?> title=<?php echo $nextday ?>>     <?php setlocale(LC_TIME, 'fra_fra'); $formatday=strftime("%A %d %B %Y", strtotime("$today +2 day")); echo $formatday?>  </option>

<option value=<?php $today=date("Y-m-d"); $nextday=date("Y-m-d", strtotime("$today +3 day")); echo $nextday?> title=<?php echo $nextday ?>>     <?php setlocale(LC_TIME, 'fra_fra'); $formatday=strftime("%A %d %B %Y", strtotime("$today +3 day")); echo $formatday?>  </option>

<option value=<?php $today=date("Y-m-d"); $nextday=date("Y-m-d", strtotime("$today +4 day")); echo $nextday?> title=<?php echo $nextday ?>>     <?php setlocale(LC_TIME, 'fra_fra'); $formatday=strftime("%A %d %B %Y", strtotime("$today +4 day")); echo $formatday?>  </option>

<option value=<?php $today=date("Y-m-d"); $nextday=date("Y-m-d", strtotime("$today +5 day")); echo $nextday?> title=<?php echo $nextday ?>>     <?php setlocale(LC_TIME, 'fra_fra'); $formatday=strftime("%A %d %B %Y", strtotime("$today +5 day")); echo $formatday?>  </option>

</select>
</td></tr>

 


MERCI !!!  A +

Hors ligne

Pied de page des forums