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 4019) - 03 April 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

wxastronomy script.........latest version

Discussion of Ken True's web site templates

Moderator: saratogaWX

tmabell
Posts: 25
Joined: Sat 07 Mar 2015 12:25 am
Weather Station: Vantage Pro II
Operating System: Windows 7
Location: Indiana

Re: wxastronomy script.........latest version

Post by tmabell »

PaulMy, I had validation issues too. Use this instead, it does validate:

Code: Select all

<h1 style="font-weight: bold; color: <?php echo $seasoncolor; ?>"><?php echo strtoupper($season); ?></h1>
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: wxastronomy script.........latest version

Post by beteljuice »

Thank you - code edited (there were more ' problems than you outlined), I was in between hospital visits and rushed it. Should be OK now.
Image
......................Imagine, what you will KNOW tomorrow !
BCJKiwi
Posts: 1256
Joined: Mon 09 Jul 2012 8:40 pm
Weather Station: Davis VP2 Cabled
Operating System: Windows 10 Pro
Location: Auckland, New Zealand
Contact:

Re: wxastronomy script.........latest version

Post by BCJKiwi »

Sorry I missed the colors - was just lifting a portion of pre-existing code (from Bashewa - credit where credit is due!!).
As always there are different paths to the same destination!
for colors my choice would be to just add

Code: Select all

   switch ($season) {
      case "Spring" :  $seasoncolor = "#32CD32"; break;
      case "Summer" :  $seasoncolor = "#FFFF00"; break;
      case "Autumn" :  $seasoncolor = "#FFD700"; break;
      case "Winter" :  $seasoncolor = "#1E90FF"; break;
      default       :  $seasoncolor = "#32CD32"; break;
   }
to the code I already posted giving;

Code: Select all

<?php
$hemi = "S"; // set to N for North, S for South Hemisphere
   $marEquinox  = mktime(0,0,0, 3,20); // approximately (Hr,Min,Sec,Mo,Day)
   $junSolstice = mktime(0,0,0, 6,21);
   $sepEquinox  = mktime(0,0,0, 9,22);
   $decSolstice = mktime(0,0,0,12,21);
   $today = time();
   switch (true) {
      case ($today>$marEquinox   && $today <= $junSolstice) :  $season = $hemi === "N"? 'Spring' : 'Autumn'; break;
      case ($today>$junSolstice  && $today <= $sepEquinox ) :  $season = $hemi === "N"? 'Summer' : 'Winter'; break;
      case ($today>$sepEquinox   && $today <= $decSolstice) :  $season = $hemi === "N"? 'Autumn' : 'Spring'; break;
      default                                               :  $season = $hemi === "N"? 'Winter' : 'Summer'; break;
   }
   switch ($season) {
      case "Spring" :  $seasoncolor = "#32CD32"; break;
      case "Summer" :  $seasoncolor = "#FFFF00"; break;
      case "Autumn" :  $seasoncolor = "#FFD700"; break;
      case "Winter" :  $seasoncolor = "#1E90FF"; break;
      default       :  $seasoncolor = "#32CD32"; break;
   }
   
echo $season;
echo $seasoncolor;
?>
If this is only used in the one place, then you could change the season names to uppercase in the switch statement then you would not require the strtoupper() in the code.

If you are baffled by the;

Code: Select all

$season = $hemi === "N"? 'Spring' : 'Autumn';
as I was when I first saw it, it is a 'short hand' method of writing an if statement using a "ternary" operator.
For a clear concise description, have a look here http://www.tuxradar.com/practicalphp/3/12/4
Note there is no multiple 'else' version of this form but any set of conditions that can fit in the ( ) of the "if" - i.e where $hemi==="N"? is - portion of the statement can be used.

For a different form of comparison using a sample of the code above;

Code: Select all

$season = $hemi === "N"     ? 'Spring'    : 'Autumn';
result  = condition_is_true ? true_result : not_true_result

Code: Select all

if ($hemi === "N")     {$season = 'Spring';}   else {$season = 'Autumn';}
if (condition_is_true) { result = true_result} else {result  = not_true_result}
So the ? is the if() and the : is the else
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: wxastronomy script.........latest version

Post by beteljuice »

Ooops ...

In the beteljuice code earlier
Edit: #2 Cut 'n' paste error in 'default' corrected.

Re. tertiary / ternary coding ...
It is possible to nest statements to effectively create multiple 'else' but it can be very difficult on the eye, especially if you don't use the (optional) brackets !!!!!

An ancient beteljuice snippet (with brackets)

Code: Select all

.($muser ? "To Change Band - Overtype<br><input type=\"text\" name=\"in1\" value=\"" .($choose=="edit" ? ereg_replace('"', "",$disp[1]) : $band). "\" size=\"25\"><br>" :  ($choose=="edit" ? ($band!=ereg_replace('"', "",$disp[1]) ? "Only Moby Can Edit This Entry<br>" .ereg_replace('"', "",$disp[1])."<br>" : ""):"")).
Scary stuff :lol: - a real b*gger to debug ....
Image
......................Imagine, what you will KNOW tomorrow !
Post Reply