Page 1 of 2

Monthly records page with PHP tags.

Posted: Tue 17 Apr 2012 6:03 pm
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

Re: Monthly records page with PHP tags.

Posted: Tue 17 Apr 2012 11:11 pm
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?>"],

Re: Monthly records page with PHP tags.

Posted: Tue 17 Apr 2012 11:41 pm
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 );

Re: Monthly records page with PHP tags.

Posted: Tue 17 Apr 2012 11:54 pm
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]

Re: Monthly records page with PHP tags.

Posted: Wed 18 Apr 2012 5:45 am
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 ?

Re: Monthly records page with PHP tags.

Posted: Wed 18 Apr 2012 11:35 am
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... ;)

Re: Monthly records page with PHP tags.

Posted: Wed 18 Apr 2012 5:43 pm
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???

Re: Monthly records page with PHP tags.

Posted: Wed 18 Apr 2012 11:30 pm
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 ;)

Re: Monthly records page with PHP tags.

Posted: Thu 19 Apr 2012 7:27 am
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:

Re: Monthly records page with PHP tags.

Posted: Thu 19 Apr 2012 8:04 am
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.

Re: Monthly records page with PHP tags.

Posted: Thu 19 Apr 2012 11:17 am
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: )

Re: Monthly records page with PHP tags.

Posted: Thu 19 Apr 2012 3:16 pm
by duke
I agree too, I was just curious ;) .

Duke

Re: Monthly records page with PHP tags.

Posted: Thu 19 Apr 2012 6:25 pm
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

Re: Monthly records page with PHP tags.

Posted: Sun 29 Apr 2012 4:35 pm
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

Re: Monthly records page with PHP tags.

Posted: Sun 29 Apr 2012 11:11 pm
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 ;)