par
Invité » 12 mars 2013, 11:37
Bonjour a tous
Voici ma demande; j'ai un tableau de visualisation de mes commandes passées et suivant le statut la ligne , que je change manuellement, change de couleur suivant son statut.
Pour automatiser ce tableau je voudrais insérer une fonction "if" qui changerai le statut quand la date de livraison prevue est supérieure a la date de création.
mon code :
Code : Tout sélectionner
<?php
// Connexion à la base de donnée
mysql_connect("****", "******", "******");
mysql_select_db('******');
// Le nom de notre table
$tablename = '*******';
// 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="6">
<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('LIV PREVUE', 'livprevue') ?></th>
<th><?php echo sort_link('LIV CONFIRMEE', 'livconfirmee') ?></th>
<th><?php echo sort_link('STATUT', 'statut') ?></th>
<th><?php echo sort_link('COMMENTAIRES', 'commentaires') ?></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='white';//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=\"175\">";
echo $row['date'];
echo "</td>
<td width=\"150\">";
echo $row['client'];
echo "</td>
<td width=\"125\">";
echo $row['ndecde'];
echo "</td>
<td width=\"150\">";
echo $row['montant'];
echo "</td>
<td width=\"150\">";
echo $row['pose'];
echo "</td>
<td width=\"150\">";
echo $row['sm'];
echo "</td>
<td width=\"150\">";
echo $row['fournisseur'];
echo "</td>
<td width=\"150\">";
echo $row['allegro'];
echo "</td>
<td width=\"150\">";
echo $row['livprevue'];
echo "</td>
<td width=\"150\">";
echo $row['livconfirmee'];
echo "</td>
<td width=\"150\">";
echo $row['statut'];
echo "</td>
<td width=\"150\">";
echo $row['commentaires'];
echo "</td>
</tr>";
?>
<?php endwhile ?>
</table>
Merci de votre aide précieuse.
Bonjour a tous
Voici ma demande; j'ai un tableau de visualisation de mes commandes passées et suivant le statut la ligne , que je change manuellement, change de couleur suivant son statut.
Pour automatiser ce tableau je voudrais insérer une fonction "if" qui changerai le statut quand la date de livraison prevue est supérieure a la date de création.
mon code :
[code]<?php
// Connexion à la base de donnée
mysql_connect("****", "******", "******");
mysql_select_db('******');
// Le nom de notre table
$tablename = '*******';
// 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="6">
<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('LIV PREVUE', 'livprevue') ?></th>
<th><?php echo sort_link('LIV CONFIRMEE', 'livconfirmee') ?></th>
<th><?php echo sort_link('STATUT', 'statut') ?></th>
<th><?php echo sort_link('COMMENTAIRES', 'commentaires') ?></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='white';//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=\"175\">";
echo $row['date'];
echo "</td>
<td width=\"150\">";
echo $row['client'];
echo "</td>
<td width=\"125\">";
echo $row['ndecde'];
echo "</td>
<td width=\"150\">";
echo $row['montant'];
echo "</td>
<td width=\"150\">";
echo $row['pose'];
echo "</td>
<td width=\"150\">";
echo $row['sm'];
echo "</td>
<td width=\"150\">";
echo $row['fournisseur'];
echo "</td>
<td width=\"150\">";
echo $row['allegro'];
echo "</td>
<td width=\"150\">";
echo $row['livprevue'];
echo "</td>
<td width=\"150\">";
echo $row['livconfirmee'];
echo "</td>
<td width=\"150\">";
echo $row['statut'];
echo "</td>
<td width=\"150\">";
echo $row['commentaires'];
echo "</td>
</tr>";
?>
<?php endwhile ?>
</table>
[/code]
Merci de votre aide précieuse.