Welcome to the Cumulus Support forum.

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

Cumulus MX V4 beta test release 4.0.0 (build 4018) - 28 March 2024

Legacy Cumulus 1 release v1.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

Monthly records page with PHP tags.

Please discuss beta versions of Cumulus 1 here. Note: There are currently no beta versions of Cumulus 1.
duke

Monthly records page with PHP tags.

Post by duke »

Continued from:here

@beteljuice

To clarify, as I'm obviously being a bit slow today, is your example below (when completed):

Code: Select all

<?php
echo "hightemp = new Array ('" .$JanTempH. "','" .$FebTempH. "','" .$MarTempH. "','" .$DecTempH. "');<br />";
?>
A direct replacement for:

Code: Select all

    hightemp = ["<?php echo $JanTempH; ?>","<?php echo $FebTempH; ?>","<?php echo $MarTempH; ?>","<?php echo $AprTempH; ?>","<?php echo $MayTempH; ?>","<?php echo $JunTempH; ?>","<?php echo $JulTempH; ?>","<?php echo $AugTempH; ?>","<?php echo $SepTempH; ?>","<?php echo $OctTempH; ?>","<?php echo $NovTempH; ?>","<?php echo $DecTempH; ?>"];
or do other parts need to be modified?

Duke
User avatar
GraemeT
Posts: 312
Joined: Wed 21 Oct 2009 11:19 am
Weather Station: La Crosse WS-2355 & WS-2306
Operating System: Windoze 7, 10, 11
Location: Bayswater, Australia
Contact:

Re: Monthly records page with PHP tags.

Post by GraemeT »

Duke,
Swap your single and double quotes...

Code: Select all

hightemp = ["<?php echo $JanTempH; ?>","<?php echo $FebTempH; ?>","<?php echo $MarTempH; ?>","<?php echo $AprTempH; ?>","<?php echo $MayTempH; ?>","<?php echo $JunTempH; ?>","<?php echo $JulTempH; ?>","<?php echo $AugTempH; ?>","<?php echo $SepTempH; ?>","<?php echo $OctTempH; ?>","<?php echo $NovTempH; ?>","<?php echo $DecTempH; ?>"];
translates to:

Code: Select all

hightemp = ["<?php echo $JanTempH.'","'.$FebTempH.'","'.$MarTempH.'","'.$AprTempH.'","'.$MayTempH.'","'.$JunTempH.'","'.$JulTempH.'","'.$AugTempH.'","'.$SepTempH.'","'.$OctTempH.'","'.$NovTempH.'","'.$DecTempH?>"],
Cheers,
Graeme.
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Monthly records page with PHP tags.

Post by beteljuice »

When the 'missing' month <#webtag>s are added, and the <br /> removed then that should be a replacement for a numeric (javascript) array.

If the array contains strings (characters), then you would need the example with the additional quotes around each <#webtag>.

It should simply replace your multiple <? echo statements for a single one.

However .... there is a 'cheat' which is easier on the eye and the mind (once you understand it).

You could (php) process ALL your JS arrays in one bundle !

See the lowtemp example below:

Code: Select all

<?php

$JanTempH = 1.0;
$FebTempH = 2.0;
$MarTempH = 3.0;
$DecTempH = 12.0;

$JanTempL = -1.0;
$FebTempL = -2.0;
$MarTempL = -3.0;
$DecTempL = -12.0;

echo "hightemp = new Array ('" .$JanTempH. "','" .$FebTempH. "','" .$MarTempH. "','" .$DecTempH. "');<br />";
echo "hightemp = new Array (" .$JanTempH. "," .$FebTempH. "," .$MarTempH. "," .$DecTempH. ");<br /><br />";

echo <<<END
lowtemp = new Array ("$JanTempL","$FebTempL","$MarTempL","$DecTempL");<br />
lowtemp = new Array ( $JanTempL , $FebTempL , $MarTempL , $DecTempL );
END;
?>
The <br /> s should NOT be included, they are just to prettify the output as it is html and not actually 'hidden' within <script> tags.

php page

Outputs:

Code: Select all

hightemp = new Array ('1','2','3','12');
hightemp = new Array (1,2,3,12);

lowtemp = new Array ("-1","-2","-3","-12");
lowtemp = new Array ( -1 , -2 , -3 , -12 );
Last edited by beteljuice on Thu 19 Apr 2012 11:07 am, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
gemini06720
Posts: 1700
Joined: Mon 10 Aug 2009 10:16 pm
Weather Station: No weather station
Operating System: No operating system
Location: World...

Re: Monthly records page with PHP tags.

Post by gemini06720 »

Duke, I have followed the previous thread and I am still unsure at what you are trying to accomplish... :oops:

As I started reading the previous thread a couple of nights a go, with my know ledge of PHP, I created a extra-webtag template, similar to the to 'webtag' template already available for Cumulus. The new monthly tags are created as arrays - because of my requirements, the template is producing two arrays for each extra-webtag. Here is a line of that template - first, the template read and processed by Cumulus:

Code: Select all

$WXX['dailyrain'] = array("<#ByMonthDailyRainH mon=1>","<#ByMonthDailyRainH mon=2>","<#ByMonthDailyRainH mon=3>","<#ByMonthDailyRainH mon=4>","<#ByMonthDailyRainH mon=5>","<#ByMonthDailyRainH mon=6>","<#ByMonthDailyRainH mon=7>","<#ByMonthDailyRainH mon=8>","<#ByMonthDailyRainH mon=9>","<#ByMonthDailyRainH mon=10>","<#ByMonthDailyRainH mon=11>","<#ByMonthDailyRainH mon=12>");

$dailyrain = 'new Array("<#ByMonthDailyRainH mon=1>","<#ByMonthDailyRainH mon=2>","<#ByMonthDailyRainH mon=3>","<#ByMonthDailyRainH mon=4>","<#ByMonthDailyRainH mon=5>","<#ByMonthDailyRainH mon=6>","<#ByMonthDailyRainH mon=7>","<#ByMonthDailyRainH mon=8>","<#ByMonthDailyRainH mon=9>","<#ByMonthDailyRainH mon=10>","<#ByMonthDailyRainH mon=11>","<#ByMonthDailyRainH mon=12>");';
The resulting PHP template:

Code: Select all

$WXX['dailyrain'] = array("35.4","60.0","23.0","10.8","23.4","27.5","10.9","141.8","31.7","331.2","39.6","22.0");

$dailyrain = 'new Array("35.4","60.0","23.0","10.8","23.4","27.5","10.9","141.8","31.7","331.2","39.6","22.0");';
The first line is used directly into the PHP template page to immediately display values as the page is loaded, before the JavaScript has time to load - my PHP template page will even/still display the extremes recorded for the current month name (such as for April) to users that might have JavaScript deactivated in their browsers.

The second line is used to 'populate' the JavaScript so other months are available once the script has been downloaded and is running on the user's computer.

To immediately display the values as the page is loaded (even if/when JavaScript is deactivated), I use the following PHP code, first at the top of the page:

Code: Select all

include_once ('cumulusXwebtags.php'); // to include the required extra-webtags
$month = (date('n')-1); // to set the current month number as a variable
Then, to display, for example, the extreme rain value that was recorded for the current month name (such as for the month of April):

Code: Select all

  <tr class="td_rainfall_data">
    <td style="text-align: left; padding-left: 10px;">Highest Daily Rainfall</td>
    <td style="text-align: center;"><span id="DailyRainH"><?php echo $WXX['dailyrain'][$month]; ?></span> <?php echo $WX['rainunit']; ?></td>
    <td style="text-align: center;"><span id="DailyRainHT"><?php echo $WXX['dailyrainT'][$month]; ?></span></td>
  </tr>
Sure, I could have create a template with individual tags, as GraemeT did, but that would have produced a file with more than 600 rarely-used tags - my used of arrays make it as convenient (if not more convenient) while keeping the number of tags to 50.

This resulting page: [link removed]
Last edited by gemini06720 on Sat 08 Jun 2013 11:25 am, edited 1 time in total.
User avatar
GraemeT
Posts: 312
Joined: Wed 21 Oct 2009 11:19 am
Weather Station: La Crosse WS-2355 & WS-2306
Operating System: Windoze 7, 10, 11
Location: Bayswater, Australia
Contact:

Re: Monthly records page with PHP tags.

Post by GraemeT »

Hi Ray,

Am I correct in assuming you've removed the javascript array from the webpage and replaced it with 2 php arrays in your cumulusXwebtags.php file ?
Cheers,
Graeme.
gemini06720
Posts: 1700
Joined: Mon 10 Aug 2009 10:16 pm
Weather Station: No weather station
Operating System: No operating system
Location: World...

Re: Monthly records page with PHP tags.

Post by gemini06720 »

Graeme, to continue with my previous example... :)

My extra-webtag template produces two arrays for each extra-webtag:
- one array is used for the immediate display when the page loads (or for the users with their JavaScript de-activated):

Code: Select all

...
<td style="text-align: left; padding-left: 10px;">Highest Hourly Rainfall</td>
<td style="text-align: center;"><span id="HourlyRainH"><?php echo $WXX['hourlyrain'][$month]; ?></span> <?php echo $rainunit; ?></td>
<td style="text-align: center;"><span id="HourlyRainHT"><?php echo $WXX['hourlyrainT'][$month]; ?></span></td>
...
- the second array is added to the JavaScript (replacing the original array) and is used when one one button is clicked:

Code: Select all

...
    var dailyrain = <?php echo $dailyrain; ?>;
    var dailyrainT = <?php echo $dailyrainT; ?>;
...
GraemeT wrote:Am I correct in assuming you've removed the javascript array from the webpage...
Indeed, and that results in a cleaner-looking source template... ;)
duke

Re: Monthly records page with PHP tags.

Post by duke »

Ok, there's a lot for me to chew over :shock: and i only started off wanting to convert the template to php tags like the rest of my site.

@GraemeT, thank you for listing all those tags for us in your other thread :) .

@beteljuice, got it, thank you :) .

And then Ray had to jump in with another way :bash: . Think I got it ;)

Will have to have a play the weekend. This has really evolved from what I thought was a simple tag changing exercise.

Thanks all for your input.

Duke

@beteljuice, why is your station never online???
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Monthly records page with PHP tags.

Post by beteljuice »

@Duke

... because I decided to give Lady beteljuice her garden back and removed my 30' anemometer mast !

I no longer run a fully functioning weather station, therefore cannot produce enough of my own data to run Cumulus.

Makes life interesting coding-wise, especially with the latest <#webtag>s which I can't process !

The banner is a hangover I really should remove, It automatically said "Station OFF-LINE" once the data was over an hour old ;)
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
mcrossley
Posts: 12692
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Monthly records page with PHP tags.

Post by mcrossley »

beteljuice wrote:The banner is a hangover I really should remove, It automatically said "Station OFF-LINE" once the data was over an hour old ;)
Aww, I quite like it. It wouldn't be the same to see your posts without it now. :cry:
User avatar
steve
Cumulus Author
Posts: 26702
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: Monthly records page with PHP tags.

Post by steve »

mcrossley wrote:Aww, I quite like it. It wouldn't be the same to see your posts without it now. :cry:
I agree.
Steve
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Monthly records page with PHP tags.

Post by beteljuice »

Actually, that's just reminded me, it's one of the many things that I need to point to my new server host, everythings being 'double mapped' at the moment (but not all things work, because some of the server paths have changed :bash: )
Image
......................Imagine, what you will KNOW tomorrow !
duke

Re: Monthly records page with PHP tags.

Post by duke »

I agree too, I was just curious ;) .

Duke
duke

Re: Monthly records page with PHP tags.

Post by duke »

That's better. Image
... because I decided to give Lady beteljuice her garden back and removed my 30' anemometer mast !
May be she would consider letting you have a smaller one............

Duke
duke

Re: Monthly records page with PHP tags.

Post by duke »

So what's happening (or not) here :? ...........?

Finally got 10 mins to get back to this today, as I nearly had the page completed for Graemes webtags I've stayed with that for now but will implement Rays method when time allows.

Anyway, here is the page working, and here is the script and table cut n paste into one of my template pages with

Code: Select all

onload="changeData(<?php echo $month; ?>-1);"
added to the body tag but no data shows. I also notice that the js clock no longer appears on this page with the script added..... :?

Duke
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Monthly records page with PHP tags.

Post by beteljuice »

You have changeData() in <body onload .........

Wonderfull CSS is one of the last things to be applied to a page, so the function can't "see" the ids it's trying to populate.

Put it as a seperate JS one-liner just before your closing </body> tag - should be OK ;)
Image
......................Imagine, what you will KNOW tomorrow !
Locked