problème affichage d'une date
Bonjour,
j'ai besoin d'aide :s si c'est possible
j'ai ce code, ci-dessous, qui permet d'afficher mes données récupérées de ma base mysql.
et j'ai une fonction qui permet de me convertir ma date EN->FR.
Code:
1 2 3 4 5 6 7 8 9
| function Change_formatDate($date, $format = 'fr')
{
$r = '^([0-9]{1,4}).([0-9]{1,2}).([0-9]{1,4})$';
if($format === 'en')
return ereg_replace($r, '\\3-\\2-\\1', $date);
return ereg_replace($r, '\\3/\\2/\\1', $date);
} |
et je veux appliquer cette fonction sur la date qui s'affiche pour avoir le bon format càd jj/mm/aaaa
Code:
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
| <?php
$db = mysql_connect($serveur, $login, $password);
mysql_select_db($base,$db);
$sql1 = mysql_query("SELECT id_site,nomsite,typologie,dates FROM site WHERE commune='$commune' ");
$change = mysql_fetch_array ($sql1);
if (mysql_num_rows($sql1)==0)
{echo "<br><br>Pas de site enregistrés!!<br><br><br>";}
else
{
echo '<tr><th>nomsite</th><th>Typo </th><th>dates</th></tr>';
for ($i=0; $i < mysql_num_rows($sql1); ++$i)
{
echo('<tr>');
mysql_data_seek($sql1, $i);
$change = mysql_fetch_array($sql1);
for ($col=1; $col<4; ++$col)
echo '<td>'.$change[$col].'</td>';
echo '<td><a href="modif_site.php?'.'id_site='.$change[0].'" >Modification</a></td>';
echo '</tr>';
}
}
mysql_close($db);
?> |
voila ce que j'ai essayé moi et ca marche pas.
en gros j'ai ajouté cette ligne de code:
Code:
if ($col=3) {$change[3]=Change_formatDate($change[3]);}
je me demande si vous avez une autre idée
Merci par avance.
Code:
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
| <?php
$db = mysql_connect($serveur, $login, $password);
mysql_select_db($base,$db);
$sql1 = mysql_query("SELECT id_site,nomsite,typologie,dates FROM site WHERE commune='$commune' ");
$change = mysql_fetch_array ($sql1);
if (mysql_num_rows($sql1)==0)
{echo "<br><br>Pas de site enregistrés!!<br><br><br>";}
else
{
echo '<tr><th>nomsite</th><th>Typo </th><th>dates</th></tr>';
for ($i=0; $i < mysql_num_rows($sql1); ++$i)
{
echo('<tr>');
mysql_data_seek($sql1, $i);
$change = mysql_fetch_array($sql1);
for ($col=1; $col<4; ++$col)
if ($col=3) {$change[3]=Change_formatDate($change[3]);}
echo '<td>'.$change[$col].'</td>';
echo '<td><a href="modif_site.php?'.'id_site='.$change[0].'" >Modification</a></td>';
echo '</tr>';
}
}
mysql_close($db);
?> |