views:

163

answers:

2

Hi All,

This is probably something really simple, however I am quite new to PHP, and havent done any HTML in years.

I need to get a PHP variable filled with an array of figures into Google Charts. My code for this so far is:

<img src="http://chart.apis.google.com/chart?
&chs=340x175
&chd=t:<?=$filedetail[1]?>
&cht=lc
&chtt=Test
">

However, Google reports an error, as it stops at the ?=$filedetail[1] for some reason. It doesnt seem that reading the variable is the problem, more that the API simply cant read past the start of the PHP tags.

Thanks,

Rob A.

EDIT: I have managed to make Google accept the URL, however now it is not showing anything on the chart, as its filling in the &chd=t: field with instead of the figures within that variable. The URL reads like this:

http://chart.apis.google.com/chart?&amp;chs=340x175&amp;chd=t:%3C?=$filedetail[1]?%3E&amp;cht=lc&amp;chtt=Test
+1  A: 

If oyu say Google is complaining about the ?=$filedetail, chances are you are doing this in a file that is not being parsed by PHP, for example a file that ends with .html or .htm.

You can see whether this is the case by looking into the page's source code in the browser. If you see the PHP command in the source as you wrote it above, the PHP code was never executed.

The easiest way to fix that, if that's the problem, would be to switch to a .php file extension.

Pekka
All of my files have the .php extension, I checked in the source code within the browser and it doesnt show any PHP commands. Its definately getting parsed (as I have a PHP table set up showing the array, which was put there to show that the array did work). I have made some progress... please see the edit.
Rob A
Have solved the problem now, turns out you were right in a way. It wasnt getting parsed properly, turns out I had some syntax wrong earlier on in the file. Thanks!
Rob A
A: 

In URLs, literal & should be written as &amp;

Edit: And you can't do ?&chs -- it should be ?chs. The line breaks are probably going to break the URL too...

Coronatus
I think they're variables for the Google API url.
Ben Shelock
Rob A