Vous n'êtes pas identifié(e).
Pages :: 1
Salut à tous,
j'aimerai ordonner un peu mon tableau... Il faudrait que je puisse classer mon tableau par le nombre croissant de type mais je n'y parviens pas... Si vous voyez une astuce.....
[code php]
<table border="1">
<tr><td><b>Type</b></td><td><b>Nombre</b></td><td><b>Temps Min</b></td><td><b>Temps max</b></td><td><b>Temp moyen</b></td></tr>
<?php
$sql_type = "SELECT type_csd from csd
GROUP BY TYPE_CSD;";
$req_type = mysql_query($sql_type) or die ('Erreur SQL !'.$sql_type.''.mysql_error());
while ( $data = mysql_fetch_array( $req_type ) )
{
?><tr><td><?php
$type_csd = $data['type_csd'];
print '<b>'.$type_csd.'</b>';
?></td><td><?php
$sql_count_type = " SELECT count(*) FROM CSD
WHERE TYPE_CSD='$type_csd'
ORDER BY count(*) DESC";
$req_count_type = mysql_query($sql_count_type) or die ('Erreur SQL !'.$sql_count_type.''.mysql_error());
while ( $data = mysql_fetch_array( $req_count_type) )
{
$nb_type = $data[0];
echo "$nb_type ";
}
?></td><td><?php
$sql_min = "SELECT MIN( `DUREE_CSD` )
FROM csd
WHERE TYPE_CSD = '$type_csd';";
$req_min = mysql_query($sql_min) or die ('Erreur SQL !'.$sql_min.''.mysql_error());
while ( $data = mysql_fetch_array( $req_min) )
{
$nb_type = $data[0];
echo "$nb_type "; ?> </td>
</td><?php
}
?></td><td><?php
$sql_max = "SELECT MAX( `DUREE_CSD` )
FROM csd
WHERE TYPE_CSD = '$type_csd';";
$req_max = mysql_query($sql_max) or die ('Erreur SQL !'.$sql_max.''.mysql_error());
while ( $data = mysql_fetch_array( $req_max) )
{
$nb_type = $data[0];
echo "$nb_type "; ?> </td>
</td><?php
}
?></td><td align="right"><?php
$sql_moy = "SELECT AVG( `DUREE_CSD` )
FROM csd
WHERE TYPE_CSD = '$type_csd';";
$req_moy = mysql_query($sql_moy) or die ('Erreur SQL !'.$sql_moy.''.mysql_error());
while ( $data = mysql_fetch_array( $req_moy) )
{
$nb_type = sprintf('%.2f',$data[0]);
echo "$nb_type "; ?> </td>
</td></tr><?php
}
}
$sql_count = "SELECT count(*) FROM CSD";
$req_count = mysql_query($sql_count) or die('Erreur SQL !'.$sql_count.''.mysql_error());
while ( $data = mysql_fetch_array( $req_count ) )
{
$nb_total = $data[0];
} ?>
<tr>
<td><b>Total</b></td>
<td><?php echo $nb_total;
?></td><td><?php
$sql_min = "SELECT MIN( `DUREE_CSD` )
FROM csd;";
$req_min = mysql_query($sql_min) or die ('Erreur SQL !'.$sql_min.''.mysql_error());
while ( $data = mysql_fetch_array( $req_min) )
{
$nb_type = $data[0];
echo "$nb_type "; ?> </td>
</td><?php
}
?></td><td><?php
$sql_max = "SELECT MAX( `DUREE_CSD` )
FROM csd;";
$req_max = mysql_query($sql_max) or die ('Erreur SQL !'.$sql_max.''.mysql_error());
while ( $data = mysql_fetch_array( $req_max) )
{
$nb_type = $data[0];
echo "$nb_type "; ?> </td>
</td><?php
}
?></td><td align="right"><?php
$sql_moy = "SELECT AVG( `DUREE_CSD` )
FROM csd;";
$req_moy = mysql_query($sql_moy) or die ('Erreur SQL !'.$sql_moy.''.mysql_error());
while ( $data = mysql_fetch_array( $req_moy) )
{
$nb_type = sprintf('%.2f',$data[0]);
echo "$nb_type "; ?></td><?php
}
mysql_close();
?>
</tr>
</table>
[/code]
Merci pour tout
Hors ligne
Bon des fois je me demande comment je raisonne.... J'ai trouvé beaucoup plus simple....
[codephp]
<table border="1">
<tr><td><b>Type</b></td><td><b>Nombre</b></td><td><b>Temps Min</b></td><td><b>Temps max</b></td><td><b>Temp moyen</b></td></tr>
<?php
$sql_rapport = "SELECT type_csd, count(*), min(duree_csd), max(duree_csd), avg(duree_csd) from csd
GROUP BY TYPE_CSD
ORDER BY count(*) DESC;";
$req_rapport = mysql_query($sql_rapport) or die ('Erreur SQL !'.$sql_rapport.''.mysql_error());
while ( $data = mysql_fetch_array( $req_rapport ) )
{
$type_csd = $data['type_csd'];
$nb_csd = $data['count(*)'];
$duree_max = $data['max(duree_csd)'];
$duree_min = $data['min(duree_csd)'];
$duree_moy = sprintf('%.2f',$data['avg(duree_csd)']);
print '<tr><td><b>'.$type_csd.'</b></td><td>'.$nb_csd.'</td><td>'.$duree_min.'</td><td>'.$duree_max.'</td><td align="right">'.$duree_moy.'</td></tr>';
}
$sql_count = "SELECT type_csd, count(*), min(duree_csd), max(duree_csd), avg(duree_csd) from csd";
$req_count = mysql_query($sql_count) or die('Erreur SQL !'.$sql_count.''.mysql_error());
while ( $data = mysql_fetch_array( $req_count ) )
{
$nb_csd = $data['count(*)'];
$duree_max = $data['max(duree_csd)'];
$duree_min = $data['min(duree_csd)'];
$duree_moy = sprintf('%.2f',$data['avg(duree_csd)']);
print '<tr><td><b>Total</b></td><td>'.$nb_csd.'</td><td>'.$duree_min.'</td><td>'.$duree_max.'</td><td align="right">'.$duree_moy.'</td></tr>';
}
mysql_close();
?>
</table>
[/code]
Hors ligne
Pages :: 1