I'm a little stuck - partly with my coding, and partly with some logic ... and I could really do with a fresh opinion on things to help me out of a corner.

I'm working on a project to keep track of my solar electricity generation, and I've ended up with a pretty simple MySQL database with two fields - a date field, and the generation data for that day. The script I'm writing is displaying a monthly graph, showing the daily figures for that month. This graph is generated by calling a Google Graph URL within an <img src='...'> html tag. Initially, the page loads and it's looking great (thanks to the Google graph API), but I want to be able to navigate back and forth through the months.

What I'm wanting to do is have two buttons on the page, "next month" and "previous month", which calls a php function to formulate a new URL string, which then, via javascript, presumably, updates the <img src> graphic accordingly. What I'm really trying to avoid doing, is to reload the entire page whenever I click the button - but instead, only update the graphic using <img src='...'>.

I'm getting in a terrible mess because I'm mixing Javascript (client) code with PHP (server code), and can't work out the logic to make a button call php code which ultimately, updates the graphic through javascript. I've got a basic AJAX implementation working, but the buttons don't cleanly cycle through the months (because the buttons end up being hard-coded with the next and previous months, and don't update accordingly after press number 1).

Any suggestions on how I would approach this? My Javascript skills are extremely limited, which is why I prefer to code in PHP. I feel this must be fairly simple, but I'm just approaching it from the wrong angle!

Many thanks

Ian

    If you want to have an image refresh itself on a page without a page reload, that doesn't have much to do with PHP, as you probably already know.

    Not knowing much about the setup, I'm not sure I can suggest a strategy. Is there any "logic" to the image names? That might be a starting spot. Given that the image is actually generated by Google (am I understanding this correctly?) ... I still don't see where PHP fits in.

    I share you pain, though. I've resisted learning JS a long time. Only recently am I starting to get a tiny handle on it. I think the fact that there are multiple targets (browsers) is a real put off. In PHP, if I tell it to "foo the bar", it does. But Javascript can be "way cool" when you need the browser to do stuff.....

      Further more jQuery is absurdly easy to use, along with jQuery UI. I never got into JS either until I started trying to use jQuery and it was just so much easier to do what I wanted / needed and it really helped me learn JS as well.

        Write a Reply...