le 03/09/2007 à 08:59
Probléme pour generer un cvs
La requette SQL fonctionne parfaitement sur ce script:
donc elle devrais fonctionner aussi sur ce script. Non ?
<? /*
Nom:
Creation:
Date:26.07.2007
Desc: Stats des alarmes SNR
*/?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>|Statistique| Alerts SNR</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
.mon_th_title {
background:#90929C;
color:#ffffff;
font-weight: bolder;
}
tr {
min-height: 5px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
}
h1 {
min-height: 6px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;
}
-->
</style>
</head>
<body>
<table>
<tr class="mon_th_title">
<? //Construction URL
$url = 'index.php?';
if (!empty($_GET['limit_by']))
$url.= 'limit_by='.$_GET['limit_by'].'&';
if (!empty($_GET['limit']))
$url.= 'limit='.$_GET['limit'].'&';
if (!empty($_GET['desc'])) {
if ($_GET['desc']=='yes')
$url.= 'desc=no&';
if ($_GET['desc']=='no')
$url.= 'desc=yes&';
}
else {
$url.= 'desc=no&';
}
$url.= 'order='
?>
<th><a href="<?=$url.'Month'?>">Mois</a></th>
<th><a href="<?=$url.'Month'?>">Années</a></th>
<th><a href="<?=$url.'devices'?>">Devices</a></th>
<th><a href="<?=$url.'interface'?>">Interface</a></th>
<th><a href="<?=$url.'descinterface'?>">Desc Interface</a></th>
<th><a href="<?=$url.'minor'?>">Minor</a></th>
<th><a href="<?=$url.'major'?>">Major</a></th>
<th><a href="<?=$url.'critical'?>">Critical</a></th>
</tr>
<?
$limit = "";
$where = "";
$order = "";
$desc = "";
if (!empty($_GET['limit_by'])) {
switch ($_GET['limit_by']) {
case 'rows' :
$limit = 'LIMIT 0,'.$_GET['limit'];
break;
case 'month' :
$where = 'AND MONTH >'.(limit()-$_GET['limit']);
break;
case 'devices' :
$where = 'AND Devices.name >'.(limit()-$_GET['limit']);
break;
default :
break;
}
}
else {
$limit = 'LIMIT 0,1000';
}
if (!empty($_GET['order'])) {
switch ($_GET['order']) {
case 'month' :
$order = 'ORDER BY MONTH';
break;
case 'year' :
$order = 'ORDER BY YEAR';
break;
case 'devices' :
$order = 'ORDER BY Devices.name';
break;
case 'interface' :
$order = 'ORDER BY Interfaces.name';
break;
case 'descinterface':
$order = 'ORDER BY InterfaceDesc';
break;
case 'service' :
$order = 'ORDER BY ServiceTypes.name';
break;
case 'minor' :
$order = 'ORDER BY Minor';
break;
case 'major' :
$order = 'ORDER BY Major';
break;
case 'critical' :
$order = 'ORDER BY Critical';
break;
}
}
else {
$order = 'ORDER BY History.eventdate DESC';
}
if (!empty($_GET['desc'])) {
if ($_GET['limit_by']=="devices") {
switch ($_GET['desc']) {
case 'no' :
$desc = '';
break;
case 'yes' :
$desc = 'DESC';
break;
default :
$desc = '';
break;
}
}
}
else {
$desc = '';
}
include("../include/connection.php");
//Lecture de la data base
$sql_history = mysql_query("
select
YEAR(FROM_UNIXTIME(History.eventdate)) as Year,
MONTH(FROM_UNIXTIME(History.eventdate)) as Month,
Devices.name as DeviceName,
Interfaces.name as InterfaceName,
Devices.name2 as devicesName2,
Interfaces.description as InterfaceDesc,
SUM(case StatusTypes.name when 'Normal' then 1 else 0 end) as Normal,
SUM(case StatusTypes.name when 'Minor' then 1 else 0 end) as Minor,
SUM(case StatusTypes.name when 'Major' then 1 else 0 end) as Major,
SUM(case StatusTypes.name when 'Critical' then 1 else 0 end) as Critical
from
History
inner join StatusTypes on History.statusid = StatusTypes.id
inner join Cells on History.cellid = Cells.id
inner join Interfaces on Cells.interfaceid = Interfaces.id
inner join ServiceTypes on Cells.serviceid = ServiceTypes.id
inner join Devices on Interfaces.deviceid = Devices.id
where
ServiceTypes.name = 'SNR'
group by
YEAR(FROM_UNIXTIME(History.eventdate)),
MONTH(FROM_UNIXTIME(History.eventdate)),
Devices.name,
Interfaces.name,
Interfaces.description
".$where."
".$order."
".$limit.$desc."
;");
while($data_history = mysql_fetch_array($sql_history)) {
//Tableau d'affichage
{
echo "<tr>";
//echo '<tr class="mon_tr_ok" style="background-color:'.$couleur.';">';
echo '<td bgcolor="#CCCCCC">' . $data_history['Month']."<br>"."</td>";
echo '<td bgcolor="#CCCCCC">' . $data_history['Year']. "</td>";
echo '<td bgcolor="#CCCCCC">' . $data_history['DeviceName'] . "</td>";
echo '<td bgcolor="#CCCCCC">' . $data_history['InterfaceName'] . "</td>";
echo '<td bgcolor="#CCCCCC">' . $data_history['InterfaceDesc']. "</td>";
echo '<td bgcolor="#FFFF33">' . $data_history['Minor'] . "</td>";
echo '<td bgcolor="#FF9900">' . $data_history['Major'] . "</td>";
echo '<td bgcolor="#CC0000">' . $data_history['Critical']. "</td>";
// echo "<td>" . $data_history['interfacesSnr'] . "</td>";
// echo"<td>" . $image = imagecreatefromgif ("image_test.GIF"); ."</td>";
echo "</tr>";
}
}
?>
</table>
</body>
</html>
donc elle devrais fonctionner aussi sur ce script. Non ?
