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
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

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

Thanks for your replies David and Jnerocorp.

 

David - your "fix" works just fine - of course !  I'd gotten into the position of fixing some other issues and in the process dug myself into a whole I couldn't see the way out of.  Many thanks.

 

Phil

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.