djo

Inscris le 14/08/2007 à 22:56
  • Nombre de sujets
    2
  • Nombre de messages
    11
  • Nombre de commentaires
    Aucun
  • Nombre de news
    Aucune
  • Niveau en PHP
    Débutant

Ses derniers messages sur les forums

djo
le 03/09/2007 à 08:59
Probléme pour generer un cvs
La requette SQL fonctionne parfaitement sur ce script:
<? /*
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 ?
djo
le 02/09/2007 à 15:30
Probléme pour generer un cvs
et c'est le faite de mettre des parenthèse sur la chaine sql qui fait l'erreur sur le while?
djo
le 02/09/2007 à 13:54
Probléme pour generer un cvs
Hello,

Alors j'ai changer le script qui ressemble a ceci maintenent:
<?php
header("Content-type: text/x-csv");
header("Content-disposition: attachment; filename=Historique_SNR_" . date("Ymd").".csv");

include("../include/connection.php");
//Lecture de la data base
$sql = ("
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(F0ROM_UNIXTIME(History.eventdate)),
MONTH(FROM_UNIXTIME(History.eventdate)),
Devices.name,
Interfaces.name,
Interfaces.description


;");
$resultat = mysql_query ($sql);
$list = "";
while ($snr = mysql_fetch_array ($resultat))
{
$month = $snr ['Month'];
$device = $snr ['DeviceName'];
$interface = $snr ['InterfaceName'];
$device2 = $snr ['InterfaceDesc'];
$minor = $snr ['Minor'];
$major = $snr ['Major'];
$critical = $snr ['Critical'];
$list .= "\"$month\",\"$device\",\"$interface\",\"$device2\",\"$minor\",\"$major\",\"$critical\"\r\n";
}
echo $list;
?>

mais j'ai une erreur a la ligne 42 sur le while
mysql_fetch_array(): supplied argument is not a valid MySQL result resource

la je sèche completement comment résoudre cette erreur une idée ?
djo
le 31/08/2007 à 08:57
Probléme pour generer un cvs
Merci pour le conseil mais la il y a un truc qui fonctionne pas c'est que le fichier cvs est vide il ne m'ecrit pas les donnée dans le Fichier mon code serait'il faut ?
djo
le 30/08/2007 à 15:50
Probléme pour generer un cvs
Bonjour,

Je doit generer un cvs avec le script ci dessous.
<?php
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=Historique_" . date("Ymd").".cvs");
$csv_output = "Month,DeviceName,InterfaceName,InterfaceDesc,Minor,Major,Critical";
$csv_output .= "\n";
include("../include/connection.php");
//Lecture de la data base
$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 = 'FEC'

group by
YEAR(FROM_UNIXTIME(History.eventdate)),
MONTH(FROM_UNIXTIME(History.eventdate)),
Devices.name,
Interfaces.name,
Interfaces.description



$result = mysql_query($query)
");
while($row = mysql_fetch_array($result)) {

$cvs_output = "$row[Month],$row[DeviceName],$row[InterfaceName],$row[devicesName2],$row[InterfaceDesc],$row[Ninor],$row[Major],$row[Critical]\n";
}
print $csv_output;
exit;
?>

Mais il me genere une erreur dans le cvs :
<b>Warning</b>:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/var/www/monitoring/historique/cvs.php</b> on line <b>43</b><br />

Si quelqu'un pouvais me dire ou ce trouve l'erreur car perso je ne la trouve pas merci d'avance pour l'aide.
djo
le 16/08/2007 à 18:01
Probléme avec la fonction switch
en tout cas merci pour l'aide

si jamais je met le code qui fonctionne correctement.
<?php
include("connection.php");
echo ' <h1>'.' Affichage des alarmes Manuelles'.'</h1>';
$query = "SELECT * FROM `incoming` order by id desc limit 0,1 ";
$result = mysql_query($query) or die($query . " - " . mysql_error());

echo "<br /><br />";

while ($tab = mysql_fetch_array($result)) {

switch ($tab['priority']) {
default :
$couleur = '#4fce1c';
break;
case 'minor' :
$couleur = '#f2e910';
break;
case 'major' :
$couleur = '#f89909';
break;
case 'high' :
$couleur = '#e22112';
break;
}

echo '<table>';
echo '<tr style="background-color:'.$couleur.';">';
echo '<td>'. $tab['id'] . '</td>';
echo '<td>'. $tab['subject'].'</td>';
echo '</tr>';
echo '</table>';
}

echo "<br />";

?>
djo
le 16/08/2007 à 14:10
Probléme avec la fonction switch
justement c'est la que le bas blesse je trouve pas le moyen de modifier le switch correctement pour que cela fonctionne
djo
le 16/08/2007 à 12:01
Probléme avec la fonction switch
Merci en tout cas la j'ai des choses qui s'affiche mais le couleur qui sont defini dans le switch elles ne s'affichent pas en fait dans le champ "priority" j'ai 4 valeur qui vont de normale a critical et donc j'imagine qu'il doit me manquer une instruction sql pour que cela fonctionne ?
LoadingChargement en cours