Jump to content

GD - Broken Image Problem


PhilPearson

Recommended Posts

OK, hello everyone from your newest newbie - to this forum anyway.

First thing to say is I do not claim to be the best php coder there is - as you will see when you look at my code !

Secondly, I have scoured/googled many sources to try and understand an answer to my problem without success.

 

So, please first look at this page -

 

http://www.thepearsons-ws.co.uk/php/MetMonthly.php

 

If you pick March 2011 say you see a list of data presented on the same page.  This is the effect I want to get to with a GD graph.

 

If you now try my first attempt -

 

http://www.thepearsons-ws.co.uk/php/raingraph3monthlyselect.php

 

- and pick March 2011 and Submit AND click the link you get a graph on a new page.  OK, but now what I want - I want the image on that same first page.

 

So, I have the attached code which produces this  -

 

http://www.thepearsons-ws.co.uk/php/raingraph3monthlyselect2.php

 

I have hacked the code around a bit but basically it's  -

 

PHP - form and data selection

HTML - form with pull downs

PHP - display graph.

 

The image is broken.  If I remove the HTML block completely it produces output but of course I can not vary the selection.  Any small element of HTML here destroys the image - no whitespace or such - just <html> is enough.

 

So, any clues on how to correctly structure this code would be greatly appreciated.

Regards

Phil

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/232518-gd-broken-image-problem/
Share on other sites

the easiest way to do it i guess is to use an iframe

 

<iframe src="http://www.thepearsons-ws.co.uk/php/raingraph3monthly.php?period=<?php echo $_GET['period']; ?>" width="100%" height="100%">
  <p>Your browser does not support iframes.</p>
</iframe>

 

place this code on the page where the user selects a date and clicks submit then when they submit make it goto the same page with "?period=######" at the end of course the #'s would be where the e.g 201101 would go

 

 

This is not a php problem. It seems you misunderstand some of the basics of html.  When you have an html page, I'm sure you know that when you want to include an image, that requires a ... tag.  You can not just spit out image data in the middle of html and expect that to work.

 

You were on the right track initially when you developed a script that accepts parameters and returns an image. 

 

To include that on a page simply requires that you reference your image script inside an tag.

 


 

All that you really require with the form is to have the period parameter filled in in your serverside code by getting the appropriate $_POST[] variables and adding them to the url.

 

 

No worries, it happens to all of us at some point that we miss the forest for the trees.  The important thing is that you got the more complicated things sorted out, and were able to get the graph and data generated in the first place.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.