Author |
Message |
Dawg
RavenNuke(tm) Development Team

Joined: Nov 07, 2003
Posts: 928
|
Posted:
Tue Aug 30, 2005 7:05 pm |
|
Greetings Raven,
Would you be kind enough to look through this portion of this script and give me some pointers on what needs work.
It works just fine....but i am sure there is a better way to do some of the things in it.
It is a script to the moon phases. The difference from most of the scripts is I have it built on a database of values from NOAA.
I DO NOT want you to rewrite my code. Just looking for a suggestion here and there.
I plan on releaseing it GPL when it is done.
Dawg
Code: <?
$query = "SELECT ID, Date, Percent FROM moon WHERE Date='$month/$day/$year'";
$result2 = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($newarray2 = mysql_fetch_array($result2)) {
$today_percent = $newarray2['Percent'];
$today_id =$newarray2['ID'];
$today_date =$newarray2['Date'];
}
$query = "SELECT Date, Percent FROM moon WHERE id > $today_id ORDER BY id LIMIT 1";
$result3 = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($newarray3 = mysql_fetch_array($result3)) {
$tomorrow_percent = $newarray3['Percent'];
$tomorrow_date =$newarray3['Date'];
}
$query = "SELECT Date, Percent FROM moon WHERE id < $today_id ORDER BY id LIMIT $today_id";
$result4 = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($newarray4 = mysql_fetch_array($result4)) {
$yesterday_percent = $newarray4['Percent'];
$yesterday_date =$newarray4['Date'];
}
if ($yesterday_percent < $today_percent && $today_percent < $tomorrow_percent)
{ if ($yesterday_percent < 0.13)
$moon_image_yesterday = '/new_moon.jpg';
else if ($yesterday_percent >= 0.13 && $yesterday_percent < 0.38)
$moon_image_yesterday = '/waxing_cresent.jpg';
else if ($yesterday_percent >= 0.38 && $yesterday_percent < 0.63)
$moon_image_yesterday = '/first_quarter.jpg';
else if ($yesterday_percent >= 0.63 && $yesterday_percent < 0.88)
$moon_image_yesterday = '/waxing_gibbous.jpg';
else if ($yesterday_percent >= 0.88 && $yesterday_percent <= 1.00)
$moon_image_yesterday = '/full_moon.jpg';
}
if ($yesterday_percent > $today_percent && $today_percent > $tomorrow_percent)
{ if ($yesterday_percent < 0.13)
$moon_image_yesterday = '/new_moon.jpg';
else if ($yesterday_percent >= 0.13 && $yesterday_percent < 0.38)
$moon_image_yesterday = '/waning_cresent.jpg';
else if ($yesterday_percent >= 0.38 && $yesterday_percent < 0.63)
$moon_image_yesterday = '/last_quarter.jpg';
else if ($yesterday_percent >= 0.63 && $yesterday_percent < 0.88)
$moon_image_yesterday = '/waning_gibbous.jpg';
else if ($yesterday_percent >= 0.88 && $yesterday_percent <= 1.00)
$moon_image_yesterday = '/full_moon.jpg';
}
if ($yesterday_percent < $today_percent && $today_percent > $tomorrow_percent)
{
$moon_image_yesterday = '/full_moon.jpg';
}
if ($yesterday_percent < $today_percent && $today_percent < $tomorrow_percent)
{ if ($today_percent < 0.13)
$moon_image_today = '/new_moon.jpg';
else if ($today_percent >= 0.13 && $today_percent < 0.38)
$moon_image_today = '/waxing_cresent.jpg';
else if ($today_percent >= 0.38 && $today_percent < 0.63)
$moon_image_today = '/first_quarter.jpg';
else if ($today_percent >= 0.63 && $today_percent < 0.88)
$moon_image_today = '/waxing_gibbous.jpg';
else if ($today_percent >= 0.88 && $today_percent <= 1.00)
$moon_image_today = '/full_moon.jpg';
}
if ($yesterday_percent > $today_percent && $today_percent > $tomorrow_percent)
{ if ($today_percent < 0.13)
$moon_image_today = '/new_moon.jpg';
else if ($today_percent >= 0.13 && $today_percent < 0.38)
$moon_image_today = '/waning_cresent.jpg';
else if ($today_percent >= 0.38 && $today_percent < 0.63)
$moon_image_today = '/last_quarter.jpg';
else if ($today_percent >= 0.63 && $today_percent < 0.88)
$moon_image_today = '/waning_gibbous.jpg';
else if ($today_percent >= 0.88 && $today_percent <= 1.00)
$moon_image_today = '/full_moon.jpg';
}
if ($yesterday_percent < $today_percent && $today_percent > $tomorrow_percent)
{
$moon_image_today = '/full_moon.jpg';
}
if ($yesterday_percent < $today_percent && $today_percent < $tomorrow_percent)
{ if ($tomorrow_percent < 0.13)
$moon_image_tomorrow = '/new_moon.jpg';
else if ($tomorrow_percent >= 0.13 && $tomorrow_percent < 0.38)
$moon_image_tomorrow = '/waxing_cresent.jpg';
else if ($tomorrow_percent >= 0.38 && $tomorrow_percent < 0.63)
$moon_image_tomorrow = '/first_quarter.jpg';
else if ($tomorrow_percent >= 0.63 && $tomorrow_percent < 0.88)
$moon_image_tomorrow = '/waxing_gibbous.jpg';
else if ($tomorrow_percent >= 0.88 && $tomorrow_percent <= 1.00)
$moon_image_tomorrow = '/full_moon.jpg';
}
if ($yesterday_percent > $today_percent && $today_percent > $tomorrow_percent)
{ if ($tomorrow_percent < 0.13)
$moon_image_tomorrow = '/new_moon.jpg';
else if ($tomorrow_percent >= 0.13 && $tomorrow_percent < 0.38)
$moon_image_tomorrow = '/waning_cresent.jpg';
else if ($tomorrow_percent >= 0.38 && $tomorrow_percent < 0.63)
$moon_image_tomorrow = '/last_quarter.jpg';
else if ($tomorrow_percent >= 0.63 && $tomorrow_percent < 0.88)
$moon_image_tomorrow = '/waning_gibbous.jpg';
else if ($tomorrow_percent >= 0.88 && $tomorrow_percent <= 1.00)
$moon_image_tomorrow = '/full_moon.jpg';
}
if ($yesterday_percent < $today_percent && $today_percent > $tomorrow_percent)
{
$moon_image_tomorrow = '/full_moon.jpg';
//if ($yesterday_percent > $today_percent && $today_percent < $tomorrow_percent)
//$moon_image_tomorrow = '/full_moon.jpg';
}
?>
<table width="70%">
<tr align="center" valign="middle">
<td>
<div align="center"><img src="/modules/Charts/images<?echo $moon_image_yesterday; ?>" alt="<?echo $moon_image_yesterday; ?>" align="middle"></div>
<td><img src="/modules/Charts/images<?echo $moon_image_today; ?>" alt="<?echo $moon_image_today; ?>" align="middle">
<td><img src="/modules/Charts/images<?echo $moon_image_tomorrow; ?>" alt="<?echo $moon_image_tomorrow; ?>" align="middle">
</tr>
<tr align="center" valign="middle">
<td>
<p> </p>
<p>
<?echo $yesterday_date; ?>
</p>
<p><b>
<?echo $yesterday_percent; ?>
</b>
<td>
<p><b><font color="#FF0000">Today</font></b></p>
<p><b><font color="#FF0000"> <font color="#000000">
<?echo $today_date?>
</font> </font></b></p>
<p> <b>
<?echo $today_percent; ?>
</b></p>
<td>
<p> </p>
<p>
<?echo $tomorrow_date; ?>
</p>
<p><b>
<?echo $tomorrow_percent; ?>
</b></p>
</tr>
</table>
</div>
</center>
</table>
<br>
<center>
<div align=center></div>
</center>
</body>
</html>
|
|
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Tue Aug 30, 2005 8:22 pm |
|
Just a real quick glance would say that you could immediately gain a few cycles by changing all those subsequent IF to ELSEIF. |
|
|
|
 |
Dawg

|
Posted:
Tue Aug 30, 2005 9:12 pm |
|
Raven,
Thank You for taking the time to take a look....
I think they HAVE to be IF's. Here is the deal...think about the Moon phase like this.....
0-1-2-3-4-5-4-3-2-1-0.
What I am tring to find out is if the value from the three days is increasing or decreasing. On one side it is waxing and on the other it is waning. (waxing and waning are moon phases)
At some point you hit a stage that is in the middle.....
($yesterday_percent < $today_percent && $today_percent > $tomorrow_percent)
That is what the subsequent IF's are for.....if you look real close you will notice the change in the "<" ">"
It was the only way I could find to make it work. |
|
|
|
 |
Raven

|
Posted:
Tue Aug 30, 2005 11:29 pm |
|
I know nothing of mooning except for, well, you know
Yes, I saw the differences before I posted my first reply. So you're saying that a single record represented by $today_percent && $today_percent can exist/resolve in more than one IF block in a single pass of the logic? |
|
|
|
 |
VinDSL
Life Cycles Becoming CPU Cycles

Joined: Jul 11, 2004
Posts: 614
Location: Arizona (USA) Admin: NukeCops.com Admin: Disipal Designs Admin: Lenon.com
|
Posted:
Wed Aug 31, 2005 4:11 am |
|
Raven wrote: | I know nothing of mooning except for, well, you know |
I was mooned by a carload of #000000 kids in Hollywood once.
The key was beeping the car horn, so I looked over at them...  |
_________________ .:: "The further in you go, the bigger it gets!" ::.
.:: Only registered users can see links on this board! Get registered or login! | Only registered users can see links on this board! Get registered or login! ::. |
|
 |
 |
Dawg

|
Posted:
Wed Aug 31, 2005 10:27 am |
|
In trying to explain what I did.....I "Think" I see what you are talking about.....
I should just have 3 sets of "IF" statements....
One set....
($yesterday_percent < $today_percent && $today_percent < $tomorrow_percent)
Second set....
($yesterday_percent > $today_percent && $today_percent > $tomorrow_percent)
Third Set....
($yesterday_percent < $today_percent && $today_percent > $tomorrow_percent)
Then in each set do all three(yesterday, today, tomorrow) as an if-else.
Is that correct?
.....Thank You for helping me "Hear the music!"
Dawg |
|
|
|
 |
Raven

|
Posted:
Wed Aug 31, 2005 10:30 am |
|
if (one set)
elseif (second set)
else (third set) |
|
|
|
 |
|