Interprétation des données avec php
Résolu
Utilisateur anonyme
-
miramaze Messages postés 1429 Date d'inscription Statut Contributeur Dernière intervention -
miramaze Messages postés 1429 Date d'inscription Statut Contributeur Dernière intervention -
Salut à tous :D
Alors voila le problème, je n'arrive pas a interprété les données de ma db avec php pour la librairie qui doit traité mes données ensuite, le problème vient surement du fait que j'utilise la fonction php echo (je débute donc je connais pas trop les autres), la librairie en question est phplot.
Voila pour le moment ce que j'ai testé :
Merci d'avance de votre aide ;)
Théo B
Alors voila le problème, je n'arrive pas a interprété les données de ma db avec php pour la librairie qui doit traité mes données ensuite, le problème vient surement du fait que j'utilise la fonction php echo (je débute donc je connais pas trop les autres), la librairie en question est phplot.
Voila pour le moment ce que j'ai testé :
<?php require_once 'phplot.php'; $data = array( array('', 1800, 5), array('', 1810, 7), array('', 1820, 10), array('', 1830, 13), array('', 1840, 17), array('', 1850, 23), array('', 1860, 31), array('', 1870, 39), array('', 1880, 50), array('', 1890, 63), array('', 1900, 76), array('', 1910, 92), array('', 1920, 106), array('', 1930, 123), array('', 1940, 132), array('', 1950, 151), array('', 1960, 179), array('', 1970, 203), array('', 1980, 227), array('', 1990, 249), array('', 2000, 281), ); $plot = new PHPlot(800, 600); $plot->SetFailureImage(False); $plot->SetPrintImage(False); $plot->SetImageBorderType('plain'); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetTitle('US Population, in millions'); $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL); $plot->DrawGraph(); ?> <img src="<?php echo $plot->EncodeImage();?>" alt="Plot Image">
Merci d'avance de votre aide ;)
Théo B
A voir également:
- Interprétation des données avec php
- Fuite données maif - Guide
- Trier des données excel - Guide
- Easy php - Télécharger - Divers Web & Internet
- Sauvegarde des données - Guide
- Supprimer les données de navigation - Guide
4 réponses
Et tu as essayé de dumper les données avant de les passer à ta méthode pour voir si elles correspondaient à ce schéma ?
Hello,
j'ai recrée ta base avec des données bidon.
Le fichier graph.php qui génère donc le graphe, sans infos je suis parti du fait qu'on représente le prix et l'id sur le graphe :
Et le fichier test.php pour générer l'image :
j'ai recrée ta base avec des données bidon.
Le fichier graph.php qui génère donc le graphe, sans infos je suis parti du fait qu'on représente le prix et l'id sur le graphe :
<?php require_once 'phplot/phplot.php'; try { $bdd = new PDO('mysql:host=localhost;dbname=fac;charset=utf8', 'root', 'root', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } $response = $bdd->query("SELECT * FROM facture_2015"); $datas = array_map(function($data){ return array('', $data['prix'], $data['id']); }, $response->fetchAll()); $response->closeCursor(); $plot = new PHPlot(800, 600); $plot->SetFailureImage(False); $plot->SetPrintImage(False); $plot->SetPlotType('lines'); $plot->SetDataType('data-data'); $plot->SetDataValues($datas); $plot->SetTitle('LD Consultants 2014 - 2015'); $plot->DrawGraph(); return $plot->EncodeImage(); ?>
Et le fichier test.php pour générer l'image :
<html> <body> <?php $graph = include 'graph.php'; ?> <div class="rendu"><img src="<?php echo $graph;?>" alt="Plot Image"></div> </body> </html>
Salut !
Sa a l'aire de bien fonctionner mais j'ai des erreur au dessus du graph qui s'affiche moi :/
Et sur le graph ya pas de courbe qui s'affiche .
Voici les erreurs ;) :
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.4030 1956048 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.4579 1956992 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.5116 1957600 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.5620 1958336 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.6167 1958944 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
Merci encore de ton aide ;)
Sa a l'aire de bien fonctionner mais j'ai des erreur au dessus du graph qui s'affiche moi :/
Et sur le graph ya pas de courbe qui s'affiche .
Voici les erreurs ;) :
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.4030 1956048 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.4579 1956992 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.5116 1957600 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.5620 1958336 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
( ! ) Notice: Undefined index: prix in C:\wamp\www\graph.php on line 17
Call Stack
# Time Memory Function Location
1 0.0135 238672 {main}( ) ..\index.php:0
2 0.0253 252320 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.4030 1955792 array_map ( ) ..\graph.php:18
4 0.6167 1958944 {closure:C:\wamp\www\graph.php:16-18}( ) ..\graph.php:18
Merci encore de ton aide ;)
Sa affiche qu'une erreur cette fois mais sa affiche que ça !
pour ce code :
( ! ) Parse error: syntax error, unexpected ';' in C:\wamp\www\graph.php on line 18
Call Stack
# Time Memory Function Location
1 0.0013 238672 {main}( ) ..\index.php:0
pour ce code :
$datas = array_map(function($data){
return array('', $data['prix'], $data['id']);
}, var_dump($response->fetchAll());
$response->closeCursor();
La sa a l'air de mieux fonctionner mais sa m'affiche qu'une erreur :
Pour le code suivant :
Merci ;)
array (size=5)
0 =>
array (size=8)
'id' => string '1' (length=1)
0 => string '1' (length=1)
'societe' => string 'ld_consultants' (length=14)
1 => string 'ld_consultants' (length=14)
'mois' => string 'Janvier' (length=7)
2 => string 'Janvier' (length=7)
'montant' => string '10450' (length=5)
3 => string '10450' (length=5)
1 =>
array (size=8)
'id' => string '2' (length=1)
0 => string '2' (length=1)
'societe' => string 'ld_consultants' (length=14)
1 => string 'ld_consultants' (length=14)
'mois' => string 'Fevrier' (length=7)
2 => string 'Fevrier' (length=7)
'montant' => string '14300' (length=5)
3 => string '14300' (length=5)
2 =>
array (size=8)
'id' => string '3' (length=1)
0 => string '3' (length=1)
'societe' => string 'ld_consultants' (length=14)
1 => string 'ld_consultants' (length=14)
'mois' => string 'Mars' (length=4)
2 => string 'Mars' (length=4)
'montant' => string '11000' (length=5)
3 => string '11000' (length=5)
3 =>
array (size=8)
'id' => string '4' (length=1)
0 => string '4' (length=1)
'societe' => string 'ld_consultants' (length=14)
1 => string 'ld_consultants' (length=14)
'mois' => string 'Avril' (length=5)
2 => string 'Avril' (length=5)
'montant' => string '11825' (length=5)
3 => string '11825' (length=5)
4 =>
array (size=8)
'id' => string '5' (length=1)
0 => string '5' (length=1)
'societe' => string 'ld_consultants' (length=14)
1 => string 'ld_consultants' (length=14)
'mois' => string 'Mai' (length=3)
2 => string 'Mai' (length=3)
'montant' => string '18425' (length=5)
3 => string '18425' (length=5)
( ! ) Fatal error: DrawGraph(): No data array in C:\wamp\www\phplot\phplot.php on line 1957
Call Stack
# Time Memory Function Location
1 0.0076 238048 {main}( ) ..\index.php:0
2 0.0084 252432 include( 'C:\wamp\www\graph.php' ) ..\index.php:3
3 0.8067 3032032 PHPlot->DrawGraph( ) ..\graph.php:33
4 0.8067 3032664 PHPlot->CheckDataArray( ) ..\phplot.php:7484
5 0.8067 3032904 PHPlot->PrintError( ) ..\phplot.php:2380
6 0.8067 3033000 trigger_error ( ) ..\phplot.php:1957
Pour le code suivant :
<?php
require_once 'phplot/phplot.php';
try
{
$bdd = new PDO('mysql:host=localhost;dbname=comptabilite_sncf;charset=utf8', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
$response = $bdd->query("SELECT * FROM facture_2015");
var_dump($response->fetchAll());
$datas = array_map(function($data){
return array('', $data['prix'], $data['id']);
}, $response->fetchAll());
$response->closeCursor();
$plot = new PHPlot(800, 600);
$plot->SetFailureImage(False);
$plot->SetPrintImage(False);
$plot->SetPlotType('lines');
$plot->SetDataType('data-data');
$plot->SetDataValues($datas);
$plot->SetTitle('LD Consultants 2014 - 2015');
$plot->DrawGraph();
return $plot->EncodeImage();
?>
Merci ;)
Le premier array dans le array_map ne va rien faire, il n'est assigné à aucune variable, n'est pas retourné, c'est du code sans effet.
Regarde la doc de array_map : https://www.php.net/manual/fr/function.array-map.php.
Voilà un exemple avec 4 graphiques sans base de donnée avec des données bidon.
Regarde la doc de array_map : https://www.php.net/manual/fr/function.array-map.php.
Voilà un exemple avec 4 graphiques sans base de donnée avec des données bidon.
<?php require_once 'phplot/phplot.php'; $datas = array( array('2001', 18, 5, 20, 1), array('2002', 18, 7, 22, 4), array('2003', 18, 10, 24, 7), array('2004', 18, 13, 26, 10), array('2005', 18, 17, 28, 13), array('2006', 18, 23, 30, 16), array('2007', 18, 31, 32, 19), array('2008', 18, 39, 34, 22), array('2009', 18, 50, 36, 25), array('2010', 18, 63, 38, 28), array('2011', 19, 76, 40, 28), array('2012', 19, 92, 42, 31), array('2013', 19, 106, 44, 34), array('2014', 19, 123, 46, 37), array('2015', 19, 132, 48, 40), array('2016', 19, 151, 50, 43), array('2017', 19, 179, 52, 46), array('2018', 19, 203, 54, 49), array('2019', 19, 227, 56, 51), array('2020', 19, 249, 58, 54), array('2021', 20, 281, 60, 59), ); $chartDatas = array_map(function($data){ return array($data[0], $data[1], $data[2], $data[3], $data[4]); }, $datas); $plot = new PHPlot(800, 600); $plot->SetFailureImage(false); $plot->SetPrintImage(false); $plot->SetPlotType('lines'); $plot->SetDataType('text-data'); $plot->SetDataValues($chartDatas); $plot->SetTitle('Charts'); $plot->SetLegend(array('Graph 1', 'Graph 2', 'Graph 3', 'Graph 4')); $plot->DrawGraph(); return $plot->EncodeImage(); ?>
Ah d'accord, j'ai compris le principe.Mais donc pour que les données soient sur une base de données je remplace les valeurs des "array" par une variable ?
Comme ceci :
Comme ceci :
<?php require_once 'phplot/phplot.php'; $datas = array( array('2001', $data['montant'], $data['id']), array('2002', $data['montant'], $data['id']), ); $chartDatas = array_map(function($data){ return array($data[0], $data[1]); }, $datas); $plot = new PHPlot(800, 600); $plot->SetFailureImage(false); $plot->SetPrintImage(false); $plot->SetPlotType('lines'); $plot->SetDataType('text-data'); $plot->SetDataValues($chartDatas); $plot->SetTitle('Charts'); $plot->SetLegend(array('Graph 1', 'Graph 2')); $plot->DrawGraph(); return $plot->EncodeImage(); ?>
Pour me connecter je fais comme ça:
<code php>
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=;charset=utf8', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
$reponse = $bdd->query('SELECT * FROM facture_2015');
while ($donnees = $reponse->fetch())
{
?>
<p>
La societe <?php echo $donnees['societe']; ?>.
</p>
<?php
}
$reponse->closeCursor();
?>
</code php>
Et ensuite pour le diagramme je fais comme j'ajoute le code qu'il y a au début .
Merci encore de t'on aide ;)
C'est un exemple avec un seul point sur le graphique juste pour les test, sa fonctionne pas :/
Merci de ton aide ;)
#| Nom| Type|
1| id | int(11)| auto_increment
2| societe| varchar(255)|
3| mois| varchar(255)|
4| prix| int(11)|
Merci de ton aide :)