Enregistrement automatique de champs
Posté : 24 mai 2013, 15:32
Bonjour a toutes et tous,
Voici ma question,
J'ai une formule de type "if" dans ma page php qui me donne un résultat, et je voudrai que ce resultat s'enregistre dans ma base de donnée.
Comment faut il faire ??
Mon code :
Merci de vos réponses
Voici ma question,
J'ai une formule de type "if" dans ma page php qui me donne un résultat, et je voudrai que ce resultat s'enregistre dans ma base de donnée.
Comment faut il faire ??
Mon code :
<?php
// Connexion à la base de donnée
mysql_connect("localhost", "xxxx", "xxxxxx");
mysql_select_db('xxxx');
// Le nom de notre table
$tablename = 'personnes';
// Tri sur colonne
$tri_autorises = array('date', 'client','ndecde','montant','pose','sm','fournisseur','allegro','livprevue','livconfirmee','statut');
$order_by = in_array($_GET['order'],$tri_autorises) ? $_GET['order'] : 'date'; 'client';'ndecde';'montant';'pose';'sm';'fournisseur';'allegro';'livprevue';'livconfirmee';'statut';
// Sens du tri
$order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC';
// Préparation de la requête
$sql = "
SELECT *
FROM {$tablename}
ORDER BY {$order_by} {$order_dir}
";
$result = mysql_query($sql);
// Notre fonction qui affiche les liens
function sort_link($text, $order=false)
{
global $order_by, $order_dir;
if(!$order)
$order = $text;
$link = '<a href="?order=' . $order;
if($order_by==$order && $order_dir=='ASC')
$link .= '&inverse=true';
$link .= '"';
if($order_by==$order && $order_dir=='ASC')
$link .= ' class="order_asc"';
elseif($order_by==$order && $order_dir=='DESC')
$link .= ' class="order_desc"';
$link .= '>' . $text . '</a>';
return $link;
}
// Affichage
?>
<style type="text/css">
a.order_asc,
a.order_desc:hover {
padding-right:15px;
background:transparent url(s_asc.png) right no-repeat;
}
a.order_desc,
a.order_asc:hover {
padding-right:15px;
background:transparent url(s_desc.png) right no-repeat;
}
</style>
<table width="100%" border="1">
<tr>
<th><?php echo sort_link('DATE', 'date') ?></th>
<th><?php echo sort_link('CLIENT', 'client') ?></th>
<th><?php echo sort_link('N° DE CDE', 'ndecde') ?></th>
<th><?php echo sort_link('MONTANT', 'montant') ?></th>
<th><?php echo sort_link('POSE', 'pose') ?></th>
<th><?php echo sort_link('S/M', 'sm') ?></th>
<th><?php echo sort_link('FOURNISSEUR', 'fournisseur') ?></th>
<th><?php echo sort_link('ALLEGRO', 'allegro') ?></th>
<th><?php echo sort_link('LIVRAISON PREVUE', 'livprevue') ?></th>
<th><?php echo sort_link('LIVRAISON CONFIRMEE', 'livconfirmee') ?></th>
<th><?php echo sort_link('COMMENTAIRES', 'commentaires') ?></th>
<th><?php echo sort_link('STATUT', 'statut') ?></th>
<th><?php echo sort_link('ETAT', '-') ?></th>
</th>
</tr>
<?php while( $row=mysql_fetch_assoc($result) ) : ?>
<tr>
<?php
switch ($row['statut']){
case 'EN COURS':
$couleur='orange';//a remplacer par le code hexa de la couleur voulue #.......
break;
case 'LIVRABLE':
$couleur='green';//a remplacer par le code hexa de la couleur voulue #.......
break;
case 'SOLDEE':
$couleur='gray';//a remplacer par le code hexa de la couleur voulue #.......
break;
case 'RETARD':
$couleur='red';//a remplacer par le code hexa de la couleur voulue #.......
break;
default:
$couleur= 'white';//a remplacer par le code hexa de la couleur par defaut
break;
}
echo "<tr style=\"background-color:$couleur;\">
<td width=\"100\">";
echo $row['date'];
echo "</td>
<td width=\"150\">";
echo $row['client'];
echo "</td>
<td width=\"100\">";
echo $row['ndecde'];
echo "</td>
<td width=\"100\">";
echo $row['montant'];
echo "</td>
<td width=\"150\">";
echo $row['pose'];
echo "</td>
<td width=\"50\">";
echo $row['sm'];
echo "</td>
<td width=\"250\">";
echo $row['fournisseur'];
echo "</td>
<td width=\"100\">";
echo $row['allegro'];
echo "</td>
<td width=\"100\">";
echo $row['livprevue'];
echo "</td>
<td width=\"100\">";
echo $row['livconfirmee'];
echo "</td>
<td width=\"150\">";
echo $row['commentaires'];
echo "</td>
<td width=\"100\">";
echo $row['statut'];
echo "</td>
<td width=\"200\">";
// Voici ma formule :
$madate=$row['livprevue'];
$madate1=$row['livconfirmee'];
$madate=explode("-",$madate);
$madate1=explode("-",$madate1);
$madate=mktime(0,0,0,$madate[1],$madate[2],$madate[0]);
$madate1=mktime(0,0,0,$madate1[1],$madate1[2],$madate1[0]);
$dateAujourdhui = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
if($madate<$dateAujourdhui&&$row['statut']='SOLDEE'){
echo "<span style='color:black;'>SOLDEE</span>";
}elseif($madate1>$dateAujourdhui){
echo "<span style='color:green;'>EN PRODUCTION</span>";
}elseif($madate==$dateAujourdhui&&$row['statut']=='SOLDEE'){
echo "<span style='color:black;'>SOLDEE</span>";
}elseif($madate==$dateAujourdhui&&$row['statut']=='LIVRABLE'){
echo "<span style='color:white;'>LIVRABLE</span>";
}elseif($madate<$dateAujourdhui&&$row['statut']=='LIVRABLE'){
echo "<span style='color:white;'>LIVRABLE</span>";
}elseif($madate==$dateAujourdhui){
echo "<span style='color:blue;'>DERNIER JOUR</span>";
}elseif($madate<$dateAujourdhui){
echo "<span style='color:red;'>EN RETARD</span>";
}elseif($madate>$dateAujourdhui&&$row['statut']=='LIVRABLE'){
echo "<span style='color:white;'>LIVRABLE</span>";
}else{
echo "<span style='color:black;'>EN COURS</span>";
}
?>
</tr>
<?php endwhile ?>
</table>
Merci de vos réponses