Expiration de date "timestamp" avec mysq

Fermé
stefart Messages postés 33 Date d'inscription jeudi 28 février 2008 Statut Membre Dernière intervention 10 juin 2008 - 17 avril 2008 à 17:16
doctormad Messages postés 430 Date d'inscription mercredi 28 novembre 2007 Statut Membre Dernière intervention 2 avril 2015 - 18 avril 2008 à 18:07
Bonjour,

Voila j'ai encore une question comment faire une expiration de date (exemple 30jours) a partir d'un champ "timestamp"

en effet je souhait que l'ajout dans d'annonce dans ma base expire apres 30jours a compter de la date d'insertion dans ma dase mysql :
champ : date_saisie
type : timestamp
Attributs :ON UPDATE CURRENT_TIMESTAMP
Défaut : CURRENT_TIMESTAMP

y'a t'il une possibilité pour le faire ! merci

2 réponses

doctormad Messages postés 430 Date d'inscription mercredi 28 novembre 2007 Statut Membre Dernière intervention 2 avril 2015 99
18 avril 2008 à 18:07
Re, dans ton cas le seul moyen est un script machine.

Par exemple un cron si tu es sous unix qui vérifie tout les jours par exemple si des annonces ont expiré.

Un cron n'est pas necessairement un script bash, tu peux aussi lancer l'execution d'un script php avec. Et ton script php ferait tout ce qu'il faut pour prévenir etc.

Je te renvois au tuto (un peu légéer) ce ccm qui devrait déjà te mettre sur la voie :
http://www.commentcamarche.net/faq/sujet 8447 automatiser des taches avec init et cron

Sous windows je ne peux pas te dire je connais pas dsl ^^

D'autre part si tu n'as accès au serveur mais seulement a un espace d'hébergement ftp, la seule possibilité serait de lancer manuellement ton script. Peut être avec un lanceur de tache automatique mais ca voudrait dire que ton pc tourne 24/24.
1
doctormad Messages postés 430 Date d'inscription mercredi 28 novembre 2007 Statut Membre Dernière intervention 2 avril 2015 99
17 avril 2008 à 18:01
Salut,

Ce n'est vraiment as très clair ton histoire "l'ajout dans d'annonce dans ma base".

Précise le but de la manip et le language utilisé.
0
stefart Messages postés 33 Date d'inscription jeudi 28 février 2008 Statut Membre Dernière intervention 10 juin 2008
18 avril 2008 à 09:44
salut Doctormad

oui après relecture c'est vrais que j'ai pas franchement donnée d'explication clair et encore moins de source !

je reprend donc :
Voila j'ai un site d'annonce en PHP qui après une inscription lorsque l'on ajoute une annonce la date s'incrémentes automatiquement dans la base MySql comme ça :

-- Structure de la table `annonces`
-- 

CREATE TABLE `annonces` (
  `id_annonce` tinyint(4) NOT NULL auto_increment,
  `date_saisie` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `titre` text collate latin1_german2_ci NOT NULL,
  `themes` varchar(30) collate latin1_german2_ci NOT NULL default '',
  `prix` decimal(10,2) NOT NULL default '0.00',
  `id_clients` tinyint(4) NOT NULL default '0',
  `img` varchar(100) collate latin1_german2_ci NOT NULL,
  `codebarre` varchar(100) collate latin1_german2_ci NOT NULL,
  `marque` varchar(100) collate latin1_german2_ci NOT NULL,
  `etat` varchar(100) collate latin1_german2_ci NOT NULL,
  `quantite` decimal(10,0) NOT NULL,
  PRIMARY KEY  (`id_annonce`),
  KEY `id_clients` (`id_clients`)
) ENGINE=MyISAM AUTO_INCREMENT=62 DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci COMMENT='Tb annonces' AUTO_INCREMENT=62 ;


y'a aussi une table client :

-- Structure de la table `clients`
-- 

CREATE TABLE `clients` (
  `ID` smallint(6) NOT NULL auto_increment,
  `nom` varchar(30) collate latin1_german2_ci NOT NULL default '',
  `email` varchar(50) collate latin1_german2_ci NOT NULL default '',
  `pass` varchar(20) collate latin1_german2_ci NOT NULL default '',
  `statut` varchar(10) collate latin1_german2_ci NOT NULL default 'client',
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci AUTO_INCREMENT=11 ;


Et a présent la source de la page d'ajout d'annonce :

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
	
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
  $insertSQL = sprintf("INSERT INTO annonces (titre, themes, prix, codebarre, id_clients) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['annonce'], "text"),
                       GetSQLValueString($_POST['themes'], "text"),
                       GetSQLValueString($_POST['prix'], "double"),
					   GetSQLValueString($_POST['codebarre'], "text"),
                       GetSQLValueString($_POST['id_client'], "int"));

  mysql_select_db($database_cnx_pa, $cnx_pa);
  $Result1 = mysql_query($insertSQL, $cnx_pa) or die(mysql_error());

  $insertGoTo = "menu.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_cnx_pa, $cnx_pa);
$query_rsAnnonces = "SELECT * FROM annonces";
$rsAnnonces = mysql_query($query_rsAnnonces, $cnx_pa) or die(mysql_error());
$row_rsAnnonces = mysql_fetch_assoc($rsAnnonces);
$totalRows_rsAnnonces = mysql_num_rows($rsAnnonces);


	
session_start();
//test si client déjà identifié
if ($statut != "client")
{ header("Location:login.php");}
?>

<html>
<script language="JavaScript">
          function testform(themes,prix,annonce) {
            if(themes.value=="") { themes.focus();return false }
            if(prix.value=="") { prix.focus();return false }
            if(annonce.value=="") { annonce.focus();return false }
            return true
            }
</script>

<head>
<script type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//-->
</script>
</head>
<body>

Bienvenue :<b> <?php echo $clientNom; ?> </b>- Ajouter une annonce
<!-- debut form ajout annonce -->
<form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>" name="form"  method="POST" onSubmit="return testform(this.themes,this.prix,this.annonce)">
                      <table width="80%" border="0" align="center" cellpadding="0" cellspacing="2">
                        <tr>
                          <td valign="top">Th&egrave;me*</td>
                          <td><select name="themes" id="themes"><? include ('themes.php')?></select></td>
                        </tr>
                        <tr>
                          <td valign="top">Prix*</td>
                          <td><input name="prix" type="text" id="prix" size="15">&euro; </td>
                        </tr>
                        <tr>
                          <td valign="top">Annonce*</td>
                          <td><input name="annonce" type="text" id="annonce" value="" size="60" maxlength="256">
                            <br>
                            256 caract&egrave;res maximum </td>
                        </tr>
                        <tr>
                          <td>Code Barre *  </td>
                          <td><input name="codebarre" type="text" id="codebarre">                             </td>
                        </tr>
                        <tr>
                          <td ><input type="hidden" name="MAX_FILE_SIZE" value="200000" />
                            photo</td>
                          <td ><input name="img" type="file" id="img" /></td>
                        </tr>
                        <tr>
                          <td colspan="2">
                            <div align="center"></div></td>
                        </tr>
                        <tr>
                          <td><input name="id_client" type="hidden" id="id_client" value="<?php echo $HTTP_SESSION_VARS['clientID']; ?>"></td>
                          <td>&nbsp;</td>
                        </tr>
                        <tr>
                          <td colspan="2"><div align="center">
                            <input type="submit" name="Submit2" value="Valider">
                          </div></td>
                          </tr>
                      </table>
                      <input type="hidden" name="MM_insert" value="form">                    </form>
<!-- fin form ajout annonce -->
</body>
</html>
<?php
mysql_free_result($rsAnnonces);
?>


Et je souhaiterais qu'après 30 jours l'enregistrement expire ou m'alerte (par mail) que l'inscription date de X jours
Malheureusement je ne sais absolument pas comment faire

merci de vos lumières !
0