Sandaysoft

Support forum for Cumulus weather station software
It is currently Sun May 19, 2013 9:51 pm
Please click here before posting. Help me to help you!
Useful Links: Cumulus FAQ • Enhancement requests • Wiki (documentation)
Please put your approximate location into your profile
Add your web site to the Cumulus user map
Vantage Pro2 users with firmware 3.00 should upgrade to fw 3.12 and Cumulus 1.9.4

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Monthly records page with PHP tags.
PostPosted: Tue Apr 17, 2012 6:03 pm 
Offline
User avatar

Joined: Sun Jul 03, 2011 6:23 pm
Posts: 324
Location: Eastleigh, Hampshire, UK
Weather Station: Davis VP2 - 24hr FARS
Operating System: Windows 7 - 64 bit
Continued from:here

@beteljuice

To clarify, as I'm obviously being a bit slow today, is your example below (when completed):
Code:
<?php
echo "hightemp = new Array ('" .$JanTempH. "','" .$FebTempH. "','" .$MarTempH. "','" .$DecTempH. "');<br />";
?>


A direct replacement for:
Code:
    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

_________________
Duke

Nightingale Weather PHP
Eastleigh, Hampshire, UK


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Tue Apr 17, 2012 11:11 pm 
Offline
User avatar

Joined: Wed Oct 21, 2009 11:19 am
Posts: 280
Location: Bayswater, Australia
Weather Station: La Crosse WS-2355
Operating System: Windoze 7
Duke,
Swap your single and double quotes...
Code:
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:
hightemp = ["<?php echo $JanTempH.'","'.$FebTempH.'","'.$MarTempH.'","'.$AprTempH.'","'.$MayTempH.'","'.$JunTempH.'","'.$JulTempH.'","'.$AugTempH.'","'.$SepTempH.'","'.$OctTempH.'","'.$NovTempH.'","'.$DecTempH?>"],

_________________
Graeme.
http://weather.gktnet.com/cumulus/index.htm
Image


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Tue Apr 17, 2012 11:41 pm 
Offline
User avatar

Joined: Tue Dec 09, 2008 1:37 pm
Posts: 1845
Location: Dudley, West Midlands, UK
Weather Station: None !
Operating System: XP SP3
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:
<?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:
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 );

_________________
Image
......................Imagine, what you will KNOW tomorrow !


Last edited by beteljuice on Thu Apr 19, 2012 11:07 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Tue Apr 17, 2012 11:54 pm 
Offline

Joined: Mon Aug 10, 2009 10:16 pm
Posts: 1797
Location: World...
Weather Station: No weather station
Operating System: No operating system
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:
$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:
$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:
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:
  <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: Month-By-Month Extremes


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Wed Apr 18, 2012 5:45 am 
Offline
User avatar

Joined: Wed Oct 21, 2009 11:19 am
Posts: 280
Location: Bayswater, Australia
Weather Station: La Crosse WS-2355
Operating System: Windoze 7
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 ?

_________________
Graeme.
http://weather.gktnet.com/cumulus/index.htm
Image


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Wed Apr 18, 2012 11:35 am 
Offline

Joined: Mon Aug 10, 2009 10:16 pm
Posts: 1797
Location: World...
Weather Station: No weather station
Operating System: No operating system
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:
...
<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:
...
    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... ;)


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Wed Apr 18, 2012 5:43 pm 
Offline
User avatar

Joined: Sun Jul 03, 2011 6:23 pm
Posts: 324
Location: Eastleigh, Hampshire, UK
Weather Station: Davis VP2 - 24hr FARS
Operating System: Windows 7 - 64 bit
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???

_________________
Duke

Nightingale Weather PHP
Eastleigh, Hampshire, UK


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Wed Apr 18, 2012 11:30 pm 
Offline
User avatar

Joined: Tue Dec 09, 2008 1:37 pm
Posts: 1845
Location: Dudley, West Midlands, UK
Weather Station: None !
Operating System: XP SP3
@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 !


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Thu Apr 19, 2012 7:27 am 
Online
User avatar

Joined: Thu Jan 07, 2010 9:44 pm
Posts: 2511
Location: Wilmslow, Cheshire, UK
Weather Station: Davis VP2
Operating System: XP SP3, Win 7
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:

_________________
Mark
Wilmslow Astro Weather


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Thu Apr 19, 2012 8:04 am 
Offline
Site Admin
User avatar

Joined: Mon Jun 02, 2008 6:49 pm
Posts: 17556
Location: Sanday, Orkney
Weather Station: Davis VP2
Operating System: Windows Home Server 2011
mcrossley wrote:
Aww, I quite like it. It wouldn't be the same to see your posts without it now. :cry:

I agree.

_________________
Steve
Sanday Weather
----------------------------------------------------------------------------------------------------------------------------------
Like Cumulus and want to support it? Please donate! Image


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Thu Apr 19, 2012 11:17 am 
Offline
User avatar

Joined: Tue Dec 09, 2008 1:37 pm
Posts: 1845
Location: Dudley, West Midlands, UK
Weather Station: None !
Operating System: XP SP3
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 !


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Thu Apr 19, 2012 3:16 pm 
Offline
User avatar

Joined: Sun Jul 03, 2011 6:23 pm
Posts: 324
Location: Eastleigh, Hampshire, UK
Weather Station: Davis VP2 - 24hr FARS
Operating System: Windows 7 - 64 bit
I agree too, I was just curious ;) .

Duke

_________________
Duke

Nightingale Weather PHP
Eastleigh, Hampshire, UK


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Thu Apr 19, 2012 6:25 pm 
Offline
User avatar

Joined: Sun Jul 03, 2011 6:23 pm
Posts: 324
Location: Eastleigh, Hampshire, UK
Weather Station: Davis VP2 - 24hr FARS
Operating System: Windows 7 - 64 bit
That's better. Image

Quote:
... 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

Nightingale Weather PHP
Eastleigh, Hampshire, UK


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Sun Apr 29, 2012 4:35 pm 
Offline
User avatar

Joined: Sun Jul 03, 2011 6:23 pm
Posts: 324
Location: Eastleigh, Hampshire, UK
Weather Station: Davis VP2 - 24hr FARS
Operating System: Windows 7 - 64 bit
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:
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

_________________
Duke

Nightingale Weather PHP
Eastleigh, Hampshire, UK


Top
 Profile  
 
 Post subject: Re: Monthly records page with PHP tags.
PostPosted: Sun Apr 29, 2012 11:11 pm 
Offline
User avatar

Joined: Tue Dec 09, 2008 1:37 pm
Posts: 1845
Location: Dudley, West Midlands, UK
Weather Station: None !
Operating System: XP SP3
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 !


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group