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 dernières news

Aucune news

Ses derniers sujets sur les forums

forum
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 à 10:52
Probléme avec la fonction switch
hello tous

Voila je dev un petit soft en php qui doit recuperer des instructions dans une db et part rapport a cetaines données il doit mettre une couleur de fond sous le text a afficher mais pour le moment il m'affiche une page blanche:

Voici mon code si quelqu'un avai l'amabilitée de m'aider a comprendre ou ce trouve mon erreur ca serai super:

<?php
include "connection.php";
$req = mysql_query("select id, mfrom, subject, priority from incoming order by id desc limit 0,1") or die( 'Erreur '.$req.'<br>'.mysql_error() );

while ( $row = mysql_fetch_row( $req ) )



switch ($row['priority']) {
case 1 :
$couleur = '#4fce1c';
break;
case 2 :
$couleur = '#f2e910';
break;
case 3 :
$couleur = '#f89909';
break;
case 4 :
$couleur = '#e22112';
break;
}

{
echo '<table style="background-color:'.$couleur.';">';
// echo '<tr style="background-color:'.$couleur.';">';
echo '<td>'. $row[0] .'</td>'.'<br>'.'<br>';
echo '<td>'. $row[1].'</td>' ;
echo '<td>'.'<h1>'. $row[2].'</h1>'.'</td>';
echo '</tr>';
echo '</table>';

};




?>


Merci d'avance

Ses derniers messages sur les forums

forum
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 ?

Ses derniers commentaires de news

Aucun commentaire de news

Ses derniers commentaires de sites

Aucun commentaire de sites

Ses derniers commentaires de wall

Aucun commentaire wall
LoadingChargement en cours