Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & Oracle
PHP & Oracle Forum d'entraide sur Oracle avec PHP. Avant de poster -> FAQ Oracle et Cours Oracle
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/08/2008, 17h11   #1
Membre actif
 
Inscription : avril 2007
Messages : 483
Détails du profil
Informations personnelles :
Âge : 24

Informations forums :
Inscription : avril 2007
Messages : 483
Points : 189
Points : 189
Par défaut Résultat d'une requête

Bonjour,

Voila j'ai dans un script php un petit problème pour créer un tableau de stats.

Voici mon code tout d'abord :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
//if we have the two parameters we create the graph
	if (isset($_POST['appname']) && $_POST['appname'] != null && isset($_POST['projname']) && $_POST['projname'] != null && isset($_POST['period']) && $_POST['period'] != null)
	{
		$appname = htmlentities($_POST['appname']);
 
		$projname = htmlentities($_POST['projname']);
 
		$period = htmlentities($_POST['period']);
 
		//connection to the database
		$connect = connexion();
 
		//we create the request functions of the period and we print a title
		if ($period == 'week')
		{
			$requeteSQL = 'SELECT nb_statsappli, statsappli FROM statsappliDay WHERE AppName=\''.escapeRequest($appname).'\' AND ProjName=\''.escapeRequest($projname).'\' AND to_char(day, \'IW\')=to_char(sysdate, \'IW\')';		
			echo '<h2>Graphics for week '.date('W').'</h2>';
		}
		else if ($period == 'month')
		{
			$requeteSQL = 'SELECT nb_statsappli, statsappli FROM statsappliDay WHERE AppName=\''.escapeRequest($appname).'\' AND ProjName=\''.escapeRequest($projname).'\' AND to_char(day, \'MM\')=to_char(sysdate, \'MM\')';		
			echo '<h2>Graphics for '.date('F').'</h2>';
		}
		else if ($period == 'quarter')
		{
			$requeteSQL = 'SELECT nb_statsappli, statsappli FROM statsappliDay WHERE AppName=\''.escapeRequest($appname).'\' AND ProjName=\''.escapeRequest($projname).'\' AND to_char(day, \'q\')=to_char(sysdate, \'q\')';		
			if (1 <= date('m') && date('m') <= 3)
			{
				echo '<h2>Graphics for first quarter</h2>';
			}
			else if (4 <= date('m') && date('m') <= 6)
			{
				echo '<h2>Graphics for second quarter</h2>';
			}
			else if (7 <= date('m') && date('m') <= 9)
			{
				echo '<h2>Graphics for third quarter</h2>';
			}
			else if (10 <= date('m') && date('m') <= 12)
			{
				echo '<h2>Graphics for fourth quarter</h2>';
			}
		}
		else if ($period == 'year')
		{
			$requeteSQL = 'SELECT nb_statsappli, statsappli FROM statsappliDay WHERE AppName=\''.escapeRequest($appname).'\' AND ProjName=\''.escapeRequest($projname).'\' AND to_char(day, \'YYYY\')=to_char(sysdate, \'YYYY\')';		
			echo '<h2>Graphics for year '.date('Y').'</h2>';
		}
 
		//execution of the request
		$res = requete($connect, $requeteSQL);
 
		//if the request doesn't return anything we print the error
		if (!$res['exec_req'])
		{
			$exec_err = oci_error($res['stmt']);
			$ERR_TXT = "Erreur Oracle ".$exec_err['code']." - ".$exec_err['message'];
			echo '<p>'.$ERR_TXT.'</p>';
			mail('@mail', 'Erreur lors d\'une requête SQL ...', $ERR_TXT);
		}
		//else we get the stats
		{
			$stats['ko'] = 0;
			$stats['ok'] = 0;
			while ($appstatus = oci_fetch_assoc($res['stmt']))
			{
				foreach ($appstatus as $champ => $val)
				{
					$status[$champ] = $val;
				}
				if ($status['STATSAPPLI'] == 0)
				{
					$stats['ko'] += $status['NB_STATSAPPLI'];
				}
				else if ($status['STATSAPPLI'] == 1)
				{
					$stats['ok'] += $status['NB_STATSAPPLI'];
				}
			}
 
			//if we have no state, we print a message
			if ($stats['ok'] == 0 && $stats['ko'] == 0)
			{
				echo '<p>No stats availables.</p>';
			}
			//else we print the graph
			else
			{
                                //création et affichage du graphique
                        }
		}
 
		deconnexion($connect, $res['stmt']);
	}
?>
Dans la table je stocke des stats (si l'appli est dispo ou non) et ensuite je fais le cumul de quand elle l'a été et de quand elle ne l'a pas été, c'est la fonction du petit morceau que je remet ici pour mieux le voir :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
$stats['ko'] = 0;
$stats['ok'] = 0;
while ($appstatus = oci_fetch_assoc($res['stmt']))
{
	foreach ($appstatus as $champ => $val)
	{
		$status[$champ] = $val;
	}
	if ($status['STATSAPPLI'] == 0)
	{
		$stats['ko'] += $status['NB_STATSAPPLI'];
	}
	else if ($status['STATSAPPLI'] == 1)
	{
		$stats['ok'] += $status['NB_STATSAPPLI'];
	}
}
Seulement en initialisant comme ceci les deux variables sont toujours à zero et je ne vois pas d'ou vient le problème ...

Pouvez vois m'aider ?
Merci d'avance
Sh4dow49 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/08/2008, 17h17   #2
Membre actif
 
Inscription : avril 2007
Messages : 483
Détails du profil
Informations personnelles :
Âge : 24

Informations forums :
Inscription : avril 2007
Messages : 483
Points : 189
Points : 189
En fait j'ai trouvé la réponse tout seul, il fallait mettre le 0 et 1 entre quote.
Sh4dow49 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/08/2008, 17h25   #3
Membre actif
 
Inscription : avril 2007
Messages : 483
Détails du profil
Informations personnelles :
Âge : 24

Informations forums :
Inscription : avril 2007
Messages : 483
Points : 189
Points : 189
Par contre toujours sur le même code, la page ne s'update pas comme il faut

En fait j'ai sur ma page 4 radio (semaine, mois trimestre, année)

selon le choix il affiche, grâce à javascript (ce qui permet de ne pas recharger a page) le graphique de la semaine / mois / trimestre / année en cours.

Seulement, si je sélectionne d'abord semaine, le graphique sera celui de la semaine pour chaque radio, etc pour chaque cas.

Je ne vois pas pourquoi, je ne pense pas que cela vienne du script js car j'utilise le même pour lier d'autres éléments de al même manière (qui nécesitent également des requêtes) et je n'ai pas ce problème.

Je pense plus à un problème de code ... mais je ne vois pas ou ...
Sh4dow49 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/08/2008, 17h38   #4
Membre actif
 
Inscription : avril 2007
Messages : 483
Détails du profil
Informations personnelles :
Âge : 24

Informations forums :
Inscription : avril 2007
Messages : 483
Points : 189
Points : 189
si ca peut aider j'utilise artichow pour faire les graphiques, et pour le dessiner je fais :
Code :
1
2
$graph->draw('pictures/graph.png');
echo '<img src="pictures/graph.png" alt="stats" />';
et quand je fais juste un j'ai a la place du graphique
Citation:
?PNG(et un carré ici)
Sh4dow49 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 05h00.


 
 
 
 
Partenaires

Hébergement Web