Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem passing data to php image script (newbie level )

Status
Not open for further replies.

antonb

Technical User
Nov 16, 2000
7
CA
I CANT SPOT THE MISTAKE BELOW IN AN IMG
TAG CALLING A GRAPH SCRIPT. DOES ANYONE
DETECT WHAT THE PROBLEM MIGHT BE?

Code:
         $BOB=   54  ;
         $CAROL= 44  ; 
         $ALICE= 33  ;
         ...


         $height =640;
         $width  =480;
         

         <IMG 
            SRC=&quot;myimage.php?a1=<?echo $BOB ?>&a2=<?echo $CAROL?>&a3=<?echo $ALICE?>&quot; 
          
            height=&quot;<? echo $height ?>&quot;    
             
            width=&quot;<? echo $width ?>&quot;
          >


In myimage.php, here are the data array lines:


Code:
         $graph->y_data['alpha']    = array(a1,a2,a3...);
         $graph->y_data['outline']  = array(a1,a2,a3...);


INSTEAD OF THE GRAPH, THIS TEXT APPEARS IN
THE BROWSER WINDOW (exactly this text):

&$a2=44&$a3=33 ?>

THE GRAPH IS RENDERED FINE IF I DEFINE &quot;BOB&quot;
&quot;CAROL&quot; AND &quot;ALICE&quot; INSIDE myimage.php
ITSELF. BUT OF COURSE, I NEED TO PASS DATA
TO IT FROM OUTSIDE THE SCRIPT (AND I DON'T
HAVE ACCESS TO A DATA BASE ON MY CHEAPY SITE).
I DON'T KNOW HOW TO GENERATE A TEMPORARY,
RANDOMLY NAMED FLAT TEXT FILE TO WRITE/READ TO,
WHICH I PRESUME IS THE OTHER ALTERNATIVE.
THIS METHOD ABOVE SEEMS BEST FOR MY SMALL
NUMBER OF DATA POINTS (24). ANYONE SEE THE
MISTAKE ABOVE?



got this example from VHgraph home page:
Code:
       <IMG SRC=&quot;plot.php3?param1=v1&param2=v2&quot;>


got this example from jpgraph home page:
Code:
       <img src=&quot;myimg.php?d1=2&d2=7&d3=12&quot; border=0>


 
Is the tag inside an echo, or out? If outside do you close the PHP tag? (?>)

Copy that zone of the code here Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 

Hugo, it is outside. The graph script works fine with numbers defined inside the script, and the graph script entered as the url in the image tag (...um...at least after I fixed the fonts path in the script),

Code:
<?
 $graphtitle='T-scores'; 
 $scale=         (1.25) ;
 $wideA= (640 * $scale) ;
 $highA= (480 * $scale) ;
?>

<BODY>
  
<IMG  SRC=&quot;ipqgraphA.php&quot;  
      HEIGHT=&quot;<?  echo $highA   ?>&quot;   
      WIDTH=&quot;<?   echo $wideA   ?>&quot;     >    

</BODY>

Above renders the graph fine, meaning the script itself is ok. But, below code doesn't. I do now observe that I copied the examples noted above rather mindlessly--obviously things must be in PHP mode after the question mark in order for the $variables to be interpreted. Looking at those two examples, however, I can't deduce the correct syntax to accomplish that after the ?. I tried bracketing the url section that follows the question mark, and that ends just before the closing quote of the url, with php tags, i.e, <? ?> . (wacky me). I do appreciate just how mickey mouse this matter is, so I confess I really did search a half dozen forums for helpful examples, coming up only with the two above. Alas, both assume a little more syntax proficiency than I clearly possess.

No more code strings showing in the browser now, btw, after I deleted all php comments above the image tag ( //blah..). Some mistake with one of them left some tag open, I guess. Progress, but, still no image.

Code:
 <?
   $graphtitle='T-scores'; 
   $scale=         (1.25) ;
   $wideA= (640 * $scale) ;
   $highA= (480 * $scale) ;
 ?>


<BODY>


<IMG 
  SRC=&quot;ipqgraphA.php?$a1=60&$a2=55&$a3=50&$a4=45&$a5=40&$a6=35&$a7=40&$a8=45&$a9=50&$a10=55&$a11=60&$a12=65&quot;  
  HEIGHT=&quot;<?  echo $highA   ?>&quot;
  WIDTH=&quot;<?   echo $wideA   ?>&quot;   >

  
</BODY>



Below is the relevant section of the graph script itself
Code:
<?php

error_reporting(E_ALL);
include 'classcoxcomb.php' ;//Copyright (C) 2000  Herman Veluwenkamp

$scaling=(1.25);
$wide=640 * $scaling ;
$high=480 * $scaling ;

$graph = new graph($wide, $high); 


//$graph = new graph(640, 480); 


if (isset($debug)) $graph->debug=TRUE;


// with values uncommented, graph is rendered ok;
// $a1 = 60 ; $a2 = 65 ; $a3 = 70 ; $a4 = 65 ; $a5 = 60 ; $a6 = 55 ;
// $a7 = 50 ; $a8 = 45 ; $a9 = 40 ; $a10 = 45 ; $a11 = 50 ; $a12 = 55 ;

 
 $graph->x_data  
     = array(&quot;NUR&quot;,&quot;AGR&quot;,&quot;DEF&quot;,&quot;TIM&quot;,&quot;INT&quot;,&quot;ALO&quot;,&quot;COL&quot;,&quot;MAN&quot;,&quot;DOM&quot;,&quot;ASR&quot;,&quot;EXT&quot;,&quot;AFF&quot;);
 
 $graph->y_data['alpha'] 
     = array($a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$a11,$a12);
 
 $graph->y_data['outline'] 
     = array($a1,$a2,$a3,$a4,$a5,$a6,$a7,$a8,$a9,$a10,$a11,$a12);
 
 $graph->y_format['alpha'] 
     = array('colour' => 'grayCC', 'area' => 'fill', 'legend' => 'none');

 $graph->y_format['outline']
     =  array('colour' => 'white', 'area' => 'open', 'legend' => 'none');
etc...
 
You can have problems registering vars.

If so $a1 can be different from $HTTP_GET_VARS['a1']

try placing this BEFORE the use of the values passed to the script:

extract($HTTP_GET_VARS);

If it runs ok, it extracts all the elements of the array creating new vars where the name is the keys of the array and with their values.
Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Thanks Anikin for your help!

Turns out I didn't need the extraction. I &quot;merely&quot; didn't know that, although the php variables inside the data array of the image script begin of course with $, this is not true when those variables are listed in the query string of an URL.

For other subnewbies, an example: Defined in the data array of mygraphscript.php are variables $a1, $a2 and $a3. To pass some values to those variables from outside the graph script, do this:

Code:
 < img  src=&quot;ipqgraphA.php?&a1=14&a2=15&a3=16&quot;   >

Notice that the variables names are a1, a2, and a3 in the query string, rather than $a1, $a2, and $a3. If the values to be passed are those entered in a form field on the previous webpage, I presume one can simply echo those form field variables (i.e, substitute <? echo $someformvariable ?> for the number 14 in the above example).

Hey, this is almost fun.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top