Author Topic: showing moon phase picture (PHP troubles)  (Read 5642 times)

0 Members and 1 Guest are viewing this topic.

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
showing moon phase picture (PHP troubles)
« on: January 31, 2007, 10:44:38 AM »
AAARrrrrrgggggg.........    Well Thanks to Ken, I was able to put the phase of the moon on my site:



Now, I would like to include a picture of the phases like this:



I've created all of the pictures; however, I can't get the php to work because the script that is creating the phase name is over my head (its not using regular arrays).

Here is the code that generates the phase name (above):


Code: [Select]
<?php echo , $mp->getPhaseName&#40;&#41;; ?>

The code is using info from moon-phase.cls.php by "requiring" it with this code at the top of my page:


Code: [Select]

<?php 
require 'moon-phase.cls.php';
$dateAsTimeStamp ''// no need to pass the date if you want to use the current date
$mp = new moonPhase&#40;$dateAsTimeStamp&#41;;
?>




Here is moon-phase.cls.php:

moon-phase.cls.php

Can anyone help a poor lost soul?  Is there a simple way that I can display a picture depending upon what the script shows as the "Phase Name".  I'm stumped?!?  #-o
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: showing moon phase picture (PHP troubles)
« Reply #1 on: January 31, 2007, 02:53:56 PM »
Here's a solution for you, using the moon-phase.cls.php -- it displays one of 30 pictures based on the number of days since the New Moon.

Code: [Select]
<?php 
$moonage 
$mp->getPeriodInDays&#40;&#41; - $mp->getDaysUntilNextNewMoon&#40;&#41;;

$moonagedays round&#40;$moonage,0&#41;;
if &#40;$moonagedays > 29&#41; &#123;$moonagedays = 29; &#125;
$t1 =  "Phase&#58; " $mp->getPhaseName&#40;&#41; . "; Moon at $moonagedays days in cycle";
?>

<img src="/images/moon<?php echo $moonagedays?>.gif"
alt="<?php echo $t1?>"
title="<?php echo $t1?>"
width="48" height="48" style="border: 0;" />


This assumes your have moon0.gif, moon1.gif ... moon29.gif in a /images directory.  If you need a set of moons, you can download one at http://saratoga-weather.org/moon.zip

Enjoy! and best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
Re: showing moon phase picture (PHP troubles)
« Reply #2 on: January 31, 2007, 10:59:43 PM »
Ken:

Once again you have come through.  Your code worked like a charm!  I ended up using my photos (they were a little smaller, and had the right color background).  I only had nine of them so I had to use some of them several times to make 29.  Please feel free to take a look at your handiwork:

http://eetee.us/station/station.php

It seems like I owe you a thank you on a daily basis  :!:   What would the people on this board do without you?  Thanks again!
South of the Tracks, Anchorage, KY