Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Select a graph(image) with "select .. option" html/php ?

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Select a graph(image) with "select .. option" html/php ?

Post by laulau »

Hi,
I need help in html or php code :oops:
I would like to choose which graphic (image) to display from a scrolling list:
Link to the "non working" :bash: page http://meyenheim.localweatherview.net/php/graphgw.php "EDIT it's ok now"

Here the code i've tried unsuccessfully :|
<form name="graph_s">
Ces graphiques représentent les données des dernières <select name="cy" onchange="graphgw.php" >
<option value="../images/graph1.jpg">24 heures</option>
<option value="../images/graph2.jpg">48 heures</option>

<?php $grname = selected.value ?>
</select>

</form>


<table cellpadding="0" cellspacing="0" id="Graph_menu">
<tr>
<td <img src=<?php echo $grname?> name="graphs" id="graphs" title="GraphWeather" alt="Graphique météo"/></td>
</tr>

<tr>
<td class="td_navigation_bar">:<a href="index.htm">actuelle</a>::<a href="gauges.htm">instruments</a>::<a href="today.htm">jour</a>::<a href="yesterday.htm">hier</a>::<a href="record.htm">records</a>::<a href="trends.htm">graph</a>:</td>
</tr>
</table>
your advices are welcome :)
Last edited by laulau on Sun 16 Jan 2011 4:31 pm, edited 1 time in total.
Laurent

Image
User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by nitrx »

is the path good to your graphs http://meyenheim.localweatherview.net/images/graph1.jpg and http://meyenheim.localweatherview.net/images/graph2.jpg ? You start the code in your php folder
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by laulau »

Yes the path is ok.
I've tried something else, the graph is showing but the changeimage is'nt working :(
http://meyenheim.localweatherview.net/php/graphgw1.php

EDIT :bash: i think this code is working, perhaps an update problem
Laurent

Image
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by daj »

Laurent,

You have a small, but crucial error in your HTML....

<td <img src=<?php echo $grname?> name="graphs" id="graphs" title="GraphWeather" alt="Graphique météo"/></td>

should be

<td> <img src=<?php echo $grname?> name="graphs" id="graphs" title="GraphWeather" alt="Graphique météo"/></td>

So as your HTML was malformed, javascript had a problem locating the item to change

Also, no need for PHP. I assume you want a default value (24 hours) when the page loads. Remember PHP runs on the server before it gets to the browser so there will be no value. Far better to force a value, and image, then let the user select. At the moment the $grname is returning a blank, so no graph, when the page loads initially

Try..

<form name="graph_s">
Ces graphiques représentent les données des dernières <select name="cy" onchange="graphgw.php" >
<option value="../images/graph1.jpg" selected="selected">24 heures</option>
<option value="../images/graph2.jpg">48 heures</option>
<?php $grname = selected.value ?>
</select>

</form>


<table cellpadding="0" cellspacing="0" id="Graph_menu">
<tr>
<td <img src=<?php echo $grname?"../images/graph1.jpg"> name="graphs" id="graphs" title="GraphWeather" alt="Graphique météo"/></td>
</tr>

<tr>
<td class="td_navigation_bar">:<a href="index.htm">actuelle</a>::<a href="gauges.htm">instruments</a>::<a href="today.htm">jour</a>::<a href="yesterday.htm">hier</a>::<a href="record.htm">records</a>::<a href="trends.htm">graph</a>:</td>
</tr>
</table>

Changes in red, deletions in strikeout
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by laulau »

Thanks David

Is there a way to use a PHP variable for the image name like i wanted to do in the code i've put in first post ?
Laurent

Image
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by daj »

Can you explain why, or what you want to achieve?

The variable name does not exist when it comes down to the browser; only on the server when the server is creating the HTML for the page.
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by laulau »

I have nothing in particular in "the oven"
I confused the php variables and those used in html pages :oops:
I've a lot to learn :lol:
Laurent

Image
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by daj »

laulau wrote:I have nothing in particular in "the oven"
I confused the php variables and those used in html pages :oops:
I've a lot to learn :lol:
That's ok. Let me try to explain a little and see if it helps.

There are many elements to a web page but the basic language of a web page is HTML and this is what is used to describe the page content and layout to your browser on your PC. When you open a web page your browser will expect HTML commands only. For the most part the HTML is sent to you from a web server so when you visit a web page the webserver sends HTML back.

Now, it may be the case that the web server does 'some magic' to produce the HTML, and your PC browser does not need to know any of this. One of the Magic things is PHP.

PHP only runs on a web server and never runs in the browser on the PC. So if a web page has PHP code in it, the webserver must deal with it and remove all the PHP code before sending to your browser (which only wants HTML).

So the job of PHP is to run some code (on the webserver) and produce HTML to be included in the final HTML sent to the web browser.

Simple Example

Code: Select all

<html>
<body>
<p>This is paragraph 1</p>
<?php 
echo "<p>This is paragraph 2</p>";
?>
</body>
</html>
The webserver processes this page and finds PHP between the <?php...?> tags. A special PHP processer then steps in and executes the code, and in this case (echo) prints some text, which is also HTML.

The result sent to the browser for display is

Code: Select all

<html>
<body>
<p>This is paragraph 1</p>
<p>This is paragraph 2</p>
</body>
</html>
All the PHP is removed as the web server "ran" it and produced output -- and now only HTML exists for your browser.

So, in you case if you have a PHP variable '$graph', it never gets to the browser as it is removed. It is only useful while the server is building the HTML to send to you.

Javascript was added to the HTML standard to enhance it. Javascript, by contrast, runs only on the Browser on your PC and updates the page you are currently being shown. So in your case, you use Javascript to change the graph image on the page. The whole page is NEVER sent back to the server to be re-loaded, only the small change you made to the <IMG> tag in your browser.

So,
PHP manipulates the page on the server BEFORE the browser gets it.
Javascript works on the page AFTER the browser has it

Does that help? Let me know if something doesn't make sense
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
laulau
Posts: 678
Joined: Tue 13 Oct 2009 10:52 pm
Weather Station: WeatherDuino Pro2
Operating System: Win 7
Location: Meyenheim, Alsace, FR
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by laulau »

Thanks
It's clear now ;)
Laurent

Image
User avatar
PaulMy
Posts: 4355
Joined: Sun 28 Sep 2008 11:54 pm
Weather Station: Davis VP2 Plus 24-Hour FARS
Operating System: Windows8 and Windows10
Location: Komoka, ON Canada
Contact:

Re: Select a graph(image) with "select .. option" html/php ?

Post by PaulMy »

David,
I wish I were 50 years younger and you were my teacher :clap:
VP2+
C1 www.komokaweather.com/komokaweather-ca
MX https://komokaweather.com/cumulusmx/index.htm /index.html /index.php
MX https://komokaweather.com/cumulusmxwll/index.htm /index.html /index.php
MX https:// komokaweather.com/cumulusmx4/index.htm
Image
Post Reply