Variable en php

Fermé
pathos - 22 avril 2009 à 09:31
 pathos - 22 avril 2009 à 15:10
Bonjour,
Bonjour,
j'aimerai réaliser une page php qui me stocke des valeurs dans un tableau (valeur lu dans une BDD oracle 10g)
récuperer ce tableau dans une autre page php pour pouvoir utiliser ses valeurs
voici le code actuel :
1ère page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Resultat</title>
</head>
<body bgcolor="#FFFFCC">
<?php
include("En-tete.html");
?>
</br>
</br>
<?php
include("connexionbd.php");
$parametre='';
$note='';
$row[]='';
$cpt=0;
$res= odbc_prepare($conn,"select SFBATA from ATLAS where ddate='4/22/2009' order by heure") or die ("Select impossible");
$result= odbc_execute($res) or die ("erreur d'execution de la requête");
while($row = odbc_fetch_array($res)){
$parametre .="$note[$cpt]=".$row[0].",";
$cpt++;
}

echo '<IMG SRC=CourbeJpGraphe.php?>';
?>


2ème page (pour dessiner une courbe a jpgraphe)
<?php
dl('php_gd2.dll'); // Import de la Dll pour utiliser GD avec php
include ("jpgraph1/src/jpgraph.php");
include ("jpgraph1/src/jpgraph_line.php");
//$parametre='';
$parametre = isset( $_GET['parametre'] ) & !empty( $_GET['parametre'] ) ? urldecode( $_GET['parametre'] ) : '';
/*if ($parametre == '')
echo "erreur";*/
//$ydata = array(11,3,8,12,5,1,9,13,5,7);
$ydata = array($parametre);
// Create the graph. These two calls are always required
$graph = new Graph(350,250,"auto");
$graph->SetScale("textlin");
// Create the linear plot
$lineplot=new LinePlot($ydata);
$lineplot->SetColor("blue");
// Add the plot to the graph
$graph->Add($lineplot);
// Display the graph
$graph->Stroke();

?>

sauf que cela me retourne une erreur du type (en gras la ligne ou se trouve l'erreur) :
Uninitialized string offset: 20 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 21 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 22 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 23 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 24 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 25 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 26 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 27 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 28 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 29 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 30 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 31 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 32 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Uninitialized string offset: 33 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22 PHP Notice: Undefined offset: 0 in D:\WWWRoot\service-Gas-monitoring-TS-LEA\Resultat.php on line 22



Merci d'avance

4 réponses

Bonjour

mauvaise utilisation des doubles quotes. Quant tu écris :
$parametre .="$note[$cpt]=".$row[0].",";
C'est comme si tu écrivais
$parametre .=$note['$cpt']".=".$row[0].",";
Autrement dit, l'indice de $note est le texte '$cpt' et non pas la valeur de la variable $cpt comme tu le pensais sans doute
En écrivant $parametre .=$note[$cpt]".=".$row[0].",";
ce problème-là devrait disparaître
0
Merci de ton aide
j'avais corrigé cette partie la !
maintenant j'ai :
<?php
include("connexionbd.php");
$row[]='';
$cpt=1;
$res= odbc_prepare($conn,"select SFBATA from ATLAS where ddate='4/22/2009' order by heure") or die ("Select impossible");
$result= odbc_execute($res) or die ("erreur d'execution de la requête");
while($row = odbc_fetch_row($res)){
$parametre[] .=odbc_result($res,1);
$cpt++;
}
var_dump($parametre);
echo "<IMG SRC=CourbeJpGraphe.php?$parametre>";
//echo '<IMG SRC=CourbeJpGraphe.php?'. urlencode( $parametre ) . '>';
?>

le var_dump($parametre) m'affiche
array(56) { [0]=> string(5) "23.20" [1]=> string(5) "23.20" [2]=> string(5) "23.20" [3]=> string(5) "23.19" [4]=> string(5) "23.18" [5]=> string(5) "23.16" [6]=> string(5) "23.15" [7]=> string(5) "23.14" [8]=> string(5) "23.05" [9]=> string(5) "23.14" [10]=> string(5) "23.06" [11]=> string(5) "23.13" [12]=> string(5) "23.06" [13]=> string(5) "23.12" [14]=> string(5) "23.07" [15]=> string(5) "23.11" [16]=> string(5) "23.06" [17]=> string(5) "23.09" [18]=> string(5) "23.08" [19]=> string(5) "23.08" [20]=> string(5) "23.09" [21]=> string(5) "23.07" [22]=> string(5) "23.11" [23]=> string(5) "23.07" [24]=> string(5) "23.13" [25]=> string(5) "23.13" [26]=> string(5) "23.11" [27]=> string(5) "23.09" [28]=> string(5) "23.07" [29]=> string(5) "23.08" [30]=> string(5) "23.08" [31]=> string(5) "23.07" [32]=> string(5) "23.07" [33]=> string(5) "23.07" [34]=> string(5) "23.07" [35]=> string(5) "23.07" [36]=> string(5) "23.07" [37]=> string(5) "23.07" [38]=> string(5) "23.07" [39]=> string(5) "23.07" [40]=> string(5) "23.08" [41]=> string(5) "23.09" [42]=> string(5) "23.10" [43]=> string(5) "23.11" [44]=> string(5) "23.11" [45]=> string(5) "23.12" [46]=> string(5) "23.12" [47]=> string(5) "23.14" [48]=> string(5) "23.15" [49]=> string(5) "23.17" [50]=> string(5) "23.18" [51]=> string(5) "23.19" [52]=> string(5) "23.19" [53]=> string(5) "23.19" [54]=> string(5) "23.19" [55]=> string(5) "23.19" }
ce qui correspond bien a mes valeur lu dans ma BDD !
le problème que j'ai c'est que j'aimerai que tout ses string soit de int et surtout
j'aimerai pouvoir récupérer cette variable dans ma seconde page !!!

Merci d'avance
0
Une chaîne ou un nombre, ça ne gêne pas beaucoup le PHP, il change de type facilement.
Mais dans ton cas, c'est toi qui le forces à choisir le type chaîne avec ta ligne
$parametre[] .=odbc_result($res,1);
le . avant le = est l'opérateur de concaténation de chaînes, tu l'obliges donc à traduire ton nombre en chaîne. Enlève le point, il est totalement inutile puisque tu ne concatènes en fait avec rien du tout ( un nouvel élément $parametre[] est créé à chaque fois et il est vide au départ).
Remarque que ça ne te donnera pas un int, mais (peut-être) un nombre à virgule flottante. Si tu tiens absolument à convertir en entier, il y a une fonction pour ça en PHP, regarde dans ton manuel. Je ne la connais pas par coeur parce que j'en ai rarement besoin.

Pour récupérer ces valeurs, tu peux les enregistrer dans une variable de session. mais le plus simple, surtout si tu dois en avoir beaucoup, c'est tout simplement de recommencer la requête dans la nouvelle page. Sauf bien sûr s'il y a risque de modification entre les deux pages et que c'est critique d'avoir vraiment la même liste de valeurs avant et après le changement de page.
0
pas faux , je n'y ais pas pensé !!!

Je te remercie ton aide et un peu de réflexion m'a parmis de réussir
j'ai modifier un peu mon code :
dans ma première page :

while($row = odbc_fetch_row($res)){
$parametre[] .=odbc_result($res,1);
}
?>
<br/>
<br/>
<?
//fonction spéciale pour transformer les tableau en chaînes de caractères
echo "<IMG SRC=\"CourbeJpGraphe.php?t=" . implode(",", $parametre) . "\">";

et dans la 2ème :
//opération inverse : transformer la chaine de caractères en tableau
$parametre = explode(",", $_GET["t"]);

Merci pour ton aide :)
0