1

I have a form to select month and day from a drop down but I don't know how to make it select and print out outcome

<?php
$months = array(
"Jan" => array(
"01" => "Aquarius",
"02 => "Aquarius",
......
),
"Feb" => array(
"01" => "Gemini",
"02" => "Gemini",
......
),
);

I just want to be able to display what the user has selected if they select Jan 01 they will see their sign is Aquarius

3
  • use jquery change event to identify the user selection Commented Nov 18, 2014 at 5:49
  • Are you looking to do something like -> echo $months[$_POST['month']][$_POST['day']];? Commented Nov 18, 2014 at 5:53
  • Not exactly I have a form that you can select the month and day of your birthday when you choose your month and day the multidimensional array will have the sign that corresponds to the month and day and then it will spit out the sign that corresponds. I think my knowledge of php is very primitive and now I am confused even more Commented Nov 18, 2014 at 20:50

2 Answers 2

1

Just a straight php solution could be something using the strtotime() function like:

// The date and month of person
$choosedate     =   strtotime("august 4");

// If the person has a date earlier than key 1
// then this is the key for after last date & before first
$start          =   'sign12';

// List of signs with start dates
$date['sign1']  =   strtotime("january 15");
$date['sign2']  =   strtotime("february 15");
$date['sign3']  =   strtotime("march 15");
$date['sign4']  =   strtotime("april 15");
$date['sign5']  =   strtotime("may 15");
$date['sign6']  =   strtotime("june 15");
$date['sign7']  =   strtotime("july 15");
$date['sign8']  =   strtotime("august 15");
$date['sign9']  =   strtotime("sept 15");
$date['sign10'] =   strtotime("october 15");
$date['sign11'] =   strtotime("november 15");
$date[$start]   =   strtotime("december 15");

// Loop through the dates separating out keys and times
foreach($date as $sign => $datestamp) {
        // If user month day is greater than current
        // assign current
        if($choosedate >= $datestamp)
            $currentSign    =   $sign;
        // If user month day is less than current, stop
        else
            break;
    }

// Echo current key if set, or else it will be the start sign.
// This would echo sign7
echo (!isset($currentSign))? $start:$currentSign;
Sign up to request clarification or add additional context in comments.

Comments

0

A basic idea, how it can be done,

PHP PART

$months = array(
                    "Jan" => array(
                                 "01" => "Aquarius",
                                 "02" => "Aquarius",
                                ),
                    "Feb" => array(
                                   "01" => "Gemini",
                                   "02" => "Gemini",
                                   )
                    );

JS PART

<script type="text/javascript">

$( document ).ready(function()
{

    var months_json = <?php echo json_encode($months);?>;

    console.log(months_json);

    for( m in months_json){
        //console.log(m);
        $('#m_sb').append('<option>'+m+'</option>');

    }


    $("#m_sb, #d_sb").on('change',function(){
        var month = $('#m_sb option:selected').text();
        var date  = $('#d_sb option:selected').text();

        //console.log(date+month);

        $.each(months_json, function(k,v){

            if(k == $('#m_sb option:selected').text()){
                $.each(v, function(i,j){
                     if(i == $('#d_sb option:selected').text())
                        alert(j);
                });
            }
        });

    });


});



</script>

<select name='months' id='m_sb'>

</select>

<select name='dates' id='d_sb'>
    <option>01</option>
    <option>02</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.