Gossamer Forum
Home : General : Internet Technologies :

PHP: Perplexing Issue: Astrological Signs

Quote Reply
PHP: Perplexing Issue: Astrological Signs
Hi all,

I am working on adapting a VBulletin PHP code modification for inserting and updating astrological signs into one of my PHP websites.

The modification and discussion can be found here:

http://www.vbulletin.org/...wthread/t-12660.html

The codes I was using are:

Code:

if (($my_birth_day > 20 and $my_birth_month == 03) xor ($my_birth_day < 20 and $my_birth_month == 04)) { $insert_astroid = "1"; }
elseif (($my_birth_day > 19 and $my_birth_month == 04) xor ($my_birth_day < 21 and $my_birth_month == 05)) { $insert_astroid = "2"; }
elseif (($my_birth_day > 20 and $my_birth_month == 05) xor ($my_birth_day < 22 and $my_birth_month == 06)) { $insert_astroid = "3"; }elseif (($my_birth_day > 21 and $my_birth_month == 06) xor ($my_birth_day < 23 and $my_birth_month == 07)) { $insert_astroid = "4"; }
elseif (($my_birth_day > 22 and $my_birth_month == 07) xor ($my_birth_day < 23 and $my_birth_month == 08)) { $insert_astroid = "5"; }
elseif (($my_birth_day > 22 and $my_birth_month == 08) xor ($my_birth_day < 23 and $my_birth_month == 09)) { $insert_astroid = "6"; }
elseif (($my_birth_day > 22 and $my_birth_month == 09) xor ($my_birth_day < 24 and $my_birth_month == 10)) { $insert_astroid = "7"; }elseif (($my_birth_day > 23 and $my_birth_month == 10) xor ($my_birth_day < 22 and $my_birth_month == 11)) { $insert_astroid = "8"; }
elseif (($my_birth_day > 21 and $my_birth_month == 11) xor ($my_birth_day < 22 and $my_birth_month == 12)) { $insert_astroid = "9"; }
elseif (($my_birth_day > 21 and $my_birth_month == 12) xor ($my_birth_day < 20 and $my_birth_month == 01)) { $insert_astroid = "10"; }elseif (($my_birth_day > 19 and $my_birth_month == 01) xor ($my_birth_day < 19 and $my_birth_month == 02)) { $insert_astroid = "11"; }
elseif (($my_birth_day > 18 and $my_birth_month == 02) xor ($my_birth_day < 20 and $my_birth_month == 03)) { $insert_astroid = "12"; }
else {
if (($my_birth_day > 19 and $my_birth_month == 04) xor ($my_birth_day < 21 and $my_birth_month == 05)) { $insert_astroid = "2"; }
elseif (($my_birth_day > 20 and $my_birth_month == 05) xor ($my_birth_day < 22 and $my_birth_month == 06)) { $insert_astroid = "3"; }
elseif (($my_birth_day > 21 and $my_birth_month == 06) xor ($my_birth_day < 23 and $my_birth_month == 07)) { $insert_astroid = "4"; }
elseif (($my_birth_day > 22 and $my_birth_month == 07) xor ($my_birth_day < 23 and $my_birth_month == 08)) { $insert_astroid = "5"; }
elseif (($my_birth_day > 22 and $my_birth_month == 08) xor ($my_birth_day < 23 and $my_birth_month == 09)) { $insert_astroid = "6"; }
elseif (($my_birth_day > 22 and $my_birth_month == 09) xor ($my_birth_day < 24 and $my_birth_month == 10)) { $insert_astroid = "7"; }
elseif (($my_birth_day > 23 and $my_birth_month == 10) xor ($my_birth_day < 22 and $my_birth_month == 11)) { $insert_astroid = "8"; }elseif (($my_birth_day > 21 and $my_birth_month == 11) xor ($my_birth_day < 22 and $my_birth_month == 12)) { $insert_astroid = "9"; }
elseif (($my_birth_day > 21 and $my_birth_month == 12) xor ($my_birth_day < 20 and $my_birth_month == 01)) { $insert_astroid = "10"; }
elseif (($my_birth_day > 19 and $my_birth_month == 01) xor ($my_birth_day < 19 and $my_birth_month == 02)) { $insert_astroid = "11"; }
elseif (($my_birth_day > 18 and $my_birth_month == 02) xor ($my_birth_day < 20 and $my_birth_month == 03)) { $insert_astroid = "12"; }else { $insert_astroid = ""; )
}

However, I noticed quite a few bugs with it, including the incorrect algorithym in the days for most of the astrological signs.

So, I adjusted the codes to look like the following:

Code:
function getAstrologicalID($birthday, $birthmonth) {
if ($birthmonth == 01) {
if ($birthday <= 19) {
$insert_astroid = "10";
}
else {
$insert_astroid = "11";
}
}
elseif ($birthmonth == 02) {
if ($birthday <= 18) {
$insert_astroid = "11";
}
else {
$insert_astroid = "12";
}
}
elseif ($birthmonth == 03) {
if ($birthday <= 20) {
$insert_astroid = "12";
}
else {
$insert_astroid = "1";
}
}
elseif ($birthmonth == 04) {
if ($birthday <= 19) {
$insert_astroid = "1";
}
else {
$insert_astroid = "2";
}
}
elseif ($birthmonth == 05) {
if ($birthday <= 20) {
$insert_astroid = "2";
}
else {
$insert_astroid = "3";
}
}
elseif ($birthmonth == 06) {
if ($birthday <= 20) {
$insert_astroid = "3";
}
else {
$insert_astroid = "4";
}
}
elseif ($birthmonth == 07) {
if ($birthday <= 22) {
$insert_astroid = "4";
}
else {
$insert_astroid = "5";
}
}
elseif ($birthmonth == 08) {
if ($birthday <= 22) {
$insert_astroid = "5";
}
else {
$insert_astroid = "6";
}
}
elseif ($birthmonth == 09) {
if ($birthday <= 22) {
$insert_astroid = "6";
}
else {
$insert_astroid = "7";
}
}
elseif ($birthmonth == 10) {
if ($birthday <= 22) {
$insert_astroid = "7";
}
else {
$insert_astroid = "8";
}
}
elseif ($birthmonth == 11) {
if ($birthday <= 21) {
$insert_astroid = "8";
}
else {
$insert_astroid = "9";
}
}
elseif ($birthmonth == 12) {
if ($birthday <= 21) {
$insert_astroid = "9";
}
else {
$insert_astroid = "10";
}
}
else {
$insert_astroid = "NULL";
}
return $insert_astroid;
}

Now, with both versions of the codes, all astrological signs are inserted/updated correctly, with the EXCEPTION of the virgo sign (which is astroid 6). This was reported as a bug in the above VBulletin web page I linked, but no solution has been posted there.

I've looked at many PHP manual pages and also perused through quite a few pages at the PHPBuilder Community Forums and other discussion forums, searched Google as well.

There seems to be something quirky happening with the 08 value that is not comparing correctly with either set of the above codes...

I did add some de-bugging coding into the script I am working on and here is an example of what is outputted:

2108NULL

DAY|MONTH|ASTROID

So, it looks like the proper parameters are being passed, but not recognizing 08 within the codes written above.

Any advice or suggestions for fixing this problem would be greatly appreciated.

Thanks in advance.
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Stealth: Sep 7, 2003, 12:50 PM
Quote Reply
Re: [Stealth] PHP: Perplexing Issue: Astrological Signs In reply to
The $birthmonth parameter - is that a string or an integer? If it's a string, I would try putting it in quotes. If it's an integer, I would lose the leading zeros. Not sure why that would make a difference with 08 but not the others, but it's the first issue that springs to mind from looking at the code.

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [Stealth] PHP: Perplexing Issue: Astrological Signs In reply to
Put the string in quotes... numbers 08 and less are returning NULL because the system is treating them as Octal numbers.

I would also change from using many if/elseif statements like that. It's be much faster to do something like:

Code:
function getAstrologicalID($birthday, $birthmonth)
{
$asteroid = array(
'01' => array(
'low_val' => 19,
'low' => 10,
'high' => 11,
),
'02' => array(
'low_val' => 18,
'low' => 11,
'high' => 12,
),
'03' => array(
'low_val' => 20,
'low' => 12,
'high' => 1,
),
'04' => array(
'low_val' => 19,
'low' => 1,
'high' => 2,
),
'05' => array(
'low_val' => 20,
'low' => 2,
'high' => 3,
),
'06' => array(
'low_val' => 20,
'low' => 3,
'high' => 4,
),
'07' => array(
'low_val' => 22,
'low' => 4,
'high' => 5,
),
'08' => array(
'low_val' => 22,
'low' => 5,
'high' => 6,
),
'09' => array(
'low_val' => 22,
'low' => 6,
'high' => 7,
),
'10' => array(
'low_val' => 22,
'low' => 7,
'high' => 8,
),
'11' => array(
'low_val' => 21,
'low' => 8,
'high' => 9,
),
'12' => array(
'low_val' => 21,
'low' => 9,
'high' => 10,
),
);

return ($birthday <= $asteroid[$birthmonth]['low_val']) ?
$asteroid[$birthmonth]['low'] :
$asteroid[$birthmonth]['high'];
}

Edit... played around a little more. Since basically all you're doing (according to your version of the algorithm) is checking against a date and returning a result, you can simplify even more since that result is predictable (month + 9 if <= the threshold, month + 10 if above your threshold, and subtract 12 from that value if the result is greater than 12)

So (not fully tested!):

Code:
function getAstrologicalID($birthday, $birthmonth)
{
$birthday = (int)$birthday;
$birthmonth = (int)$birthmonth;

if ($birthmonth < 1)
{
return 'NULL';
}

$lows = array(0, 19, 18, 20, 19, 20, 20, 22, 22, 22, 22, 21, 21);
$offset = ($birthday <= $lows[$birthmonth]) ? 9 : 10;
$value = $birthmonth + $offset;

return ($value <= 12) ? $value : $value - 12;
}

--mark

Last edited by:

Mark Badolato: Sep 7, 2003, 3:06 PM
Quote Reply
Re: [Mark Badolato] PHP: Perplexing Issue: Astrological Signs In reply to
Thanks, hennagaijin and Mark.

The type of character being passed was the issue...I thought that the conditions set-up would treat the param as a integer, but I need to check it as a string...with single qoutes, all checks worked for all signs.

Thanks!

Very cool codes, Mark...when I have some more time, I will try them out and probably use them in the application I am developing since they look way more efficient than my codes.

Thanks again.
========================================
Buh Bye!

Cheers,
Me