Kua / Gua Calculator for Fung Shui - Trying to derive the equation and code

Dear PHP Help,

I’m looking for help on creating an array and a formula that would calculate the gua / fung shui number of someone online.

KUA NUMBER FOR A FEMALE:

  1. Add the last two numbers of your year of birth and bring it to a single digit.

  2. Add your single digit to number 5.

  3. This is your Kua Number!

KUA NUMBER FOR A MALE:

  1. Add the last two numbers of your year of birth and bring it to a single digit.

  2. Deduct your single digit from number 10.

  3. This is your Kua Number!

There are a number of these online and it seems most rest on the premise or creating around 100 inputs into HTML and I was wondering if there was an easier way using PHP to derive the equation and set up the code.

I was hoping to have a very simple form text input where someone who have to only enter the last two digits of their birth year and then a radio button where the user would select whether they are male or female, and then a calculate button.

Any help is much appreciated. I am also happy to pay for assistance. I can be contacted directly at andrew(at)paxforfriends.com.

Best regards,

Andrew

Easy enough to do, but one question - for this single digit, are you dropping the second number completely or rounding up/down?

Here you go, on the house :wink:
[php]<?php
/**

  • Function returns Kua / Gua / Fung Shui

  • number of a male or female.

  • Expects:

  • year of birth (2 or 4 digits)

  • gender
    */
    function kua_calculator($year, $gender) {
    // make the string into an array.
    $yr = str_split($year);

    //if year is 4 digits, lose the first two.
    if(sizeof($yr) == 4) {
    array_splice($yr, 0, 2);
    }

    // get the first number of the equasion…
    $n1 = $yr[0] + $yr[1];

    /**

    • Check if male / female.
      /
      if($gender == ‘female’) {
      $n = $n1 + 5;
      }
      else {
      $n = 10 - $n1;
      }
      /
    • Return the final number.
      **/
      return $n;
      }

/**

  • Call some numbers.
    ** /
    print kua_calculator(1930, ‘male’);
    print ‘
    ’;
    print kua_calculator(1930, ‘female’);
    print ‘
    ’;
    print kua_calculator(98, ‘male’);
    print ‘
    ’;
    print kua_calculator(98, ‘female’);
    // output:
    7
    8
    -7
    22
    /**/

/**

  • Form
  • You can use the function on it’s own with the above code.
  • or as part of a form by including the bottom code… :]
    **/

/**

  • Check if the form was submitted…
    **/
    if(isset($_POST[‘submit’])) {
    print kua_calculator($_POST[‘year’], $_POST[‘gender’]);
    }
    ?>
Please Choose: <?php for($i = date('Y'); $i >= date('Y')-120; $i--) { print '' . $i . ''; } ?> Please Choose: Male Female [/php]

Using the form (which submits to itself) the user enters their info (year of birth, gender)
then when they hit submit the answer is presented on screen.
Note: I have limited the input the users can enter (male|female) and starting with the present year, I allow going back 120 years. (change this to suit your needs.)

You can use the function independently of the form by copying it where ever you need it and calling the function with the commands show commented out.

Hope that helps,
Red :wink:

Ps: If you need me again, you can find me using the link in my signature. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service