Hey i am creating an app that I need to have a certain range of months be in a drop down acording to a session variable. the user will choose a season then after two pages the months for that season wil lbe available in a dropdown to schedule events.

I was going to create an array of months and then call the months that I needed but am unsure how to code it.

I started with an array of all the months

$months(1=> jan) etc

then was having trouble setting up an if

if( $session[season] = 'Fall' ) {$ms = 8; $me =11}

then setting up a for loop to call the months array in and add one until it got to 11.

Is there an easier better way to code this?

Tom

    This is for the seasons here in Australia, but you get the idea....

    <?php
    
        $months = array(
                'january',
                'febuary',
                'march',
                'april',
                'may',
                'june',
                'july',
                'august',
                'september',
                'october',
                'november',
                'december'
        );
    
        $summer = array(11,0,1);
        $autumn = array(2,3,4);
        $winter = array(5,6,7);
        $spring = array(8,9,10);
    
        $season = 'winter'; // set this to your session as required.
    
        foreach (${$season} as $month) {
                echo $months[$month];;
    
        }
    
    ?>
    

      hey many thanks.

      I'll give that a shot tomorrow.

      Tom

        thorpe wrote:
        <?php
        
            $months = array(
                    'january',
                    'febuary',
                    'march',
                    'april',
                    'may',
                    'june',
                    'july',
                    'august',
                    'september',
                    'october',
                    'november',
                    'december'
            );
        
            $summer = array(12,1,2);
            $autumn = array(3,4,5);
            $winter = array(6,7,8);
            $spring = array(9,10,11);
        
            $season = 'winter'; // set this to your session as required.
        
            foreach (${$season} as $month) {
                    echo $months[$month];;
        
            }
        
        ?>
        

        Hmmmm... don't forget that the first item in an array is usually linked to key 0, not 1 !

          Alright I can't get it to return months. What I am trying to figure out. Is that if my session varible is 'fall' how is it going to match up with $fall.

          thanks

          Tom

            oh nevermind that is what ${$season} does right

            Tom

              I was setting the session varable wrong duh. but I am now getting this

              Warning: Invalid argument supplied for foreach() in admin.php on line 98

                If you want to use fall you will need to change the variable $autumn to $fall. You'' also need to adjust for your seasons, as I said this is for Australian seasons.

                Ive fixed the array indexing issue that Suntra pointed out also. This is really just an example, you'll need to bend it into a shape you can use.

                <?php 
                
                    $months = array( 
                            'january', 
                            'febuary', 
                            'march', 
                            'april', 
                            'may', 
                            'june', 
                            'july', 
                            'august', 
                            'september', 
                            'october', 
                            'november', 
                            'december' 
                    ); 
                
                    $summer = array(11,0,1); 
                    $fall = array(2,3,4); 
                    $winter = array(5,6,7); 
                    $spring = array(8,9,10); 
                
                    $season = 'winter'; // set this to your session as required. 
                
                    foreach (${$season} as $month) { 
                            echo $months[$month];; 
                
                    } 
                
                ?>
                

                PS: Ive tested the code and its working. Your either trying to call an array that doesnt exist (ie $fall) or something else is wrong with the way your using this code.

                If your still stuck.... post what you have.

                  Hey

                  My session varible was Spring not spring.

                  That was causing the issue.

                  Changed the form to spring and it works great

                  Thanks

                  Tom

                    Write a Reply...