Hi,
I made a select option:
<select name="month">
<option>Select Month</option>
<option value=01>January</option>


<option value=12>December</option>
</select>
So, In output, I want to display the month name(Not Value). Like this
"The record of: January". how can i store the name from select option in a variable?

    One way is to make an array of month names, and then access the array by index.

      Can u please explain me how can i do that? just giving an example...

        akaki wrote:

        Can u please explain me how can i do that? just giving an example...

        Like this...

        $monthArray = array(
        1 => 'January',
        2 => 'February',
        // fill in the rest
        );
        
        // assume $monthNum is the number of the month from your form
        echo "You chose " . $monthArray[$monthNum];
        
          $months = array('January', 'February', ...);
          
          ...
          
          echo $months[$_POST['month']];

          Of course, in this case you chose to index starting from 1, so your array might be this instead:

          $months = array(1 => 'January', 'February', ...);

            Hi, Thanks for reply. I'll try.
            But now i observed that at present in php code, most of developper create a table & retrive from there in a select option. I meant to say that, we write manualy a select option it's name & value, But good developpers create a table, store there & retrive data from there in select option, how can they do that? Any idea? for this, we can insert value from fron end & it will autometically store in database & also in select option.
            I hope u can understant it...
            Thanks

              Basically, you need to learn how to use a database with PHP. In this case storing the month names in a database would verge on 'over-engineering', since the number, order and names of months in a year are very unlikely to change.

                Hi,
                I tried, but still not displaying the numbers, not month names.
                what is meant by "monthNum"? numbers are in my select option as value(01, 02).
                main problem is i want to display month name in my report. I m selecting in 1 page & action in another page by date.
                Thanks...

                To laserlight:
                Did u do as i say in any of ur work(Not with th date)? If yes, then how? Any guideline?

                  Why do you have the value as 01, 02, etc when you don't need the number but the text name?

                  Anyway what was implied is that you select the month and then (presumably) send your form.

                  PHP captures the value of the month selector as part of the postdata. In your case it'll be

                  $monthNum = $_POST['month'];
                  

                  The suggestion then is that you use the $monthNum value to select a value from your pre-made Array of month names.

                  Note you could do this another way by using the date() function, probably in conjunction with mktime(). This has various options for taking a numeric date and producing a nice text version of it (check the manual on http://www.php.net ). In this case you'd simply need the number as you retrieve it from the postdata.

                    13 days later

                    Hello,
                    I create some search option with drop down list box. search by month is 1 of them. I've a table named orders, suppose LabOrder_No & Log_date. dates are storing in database as yy-mm-dd but im retriving as dd-mm-yy. I will select a month name from list (jan,feb....dec & their values are 01,02...12), click submit button & display the total orders & quantity of that month. to collect total quantity, i wrote a function:

                    $month = $_POST['month'];

                    function totalOrders(){
                    $q = "SELECT LabOrder_No, LogIn_Date FROM orders WHERE LogIn_Date = '$month'";
                    $r = mysql_query($q);
                    if($r){
                    while($data = mysql_fetch_array($r))
                    $total = $total + count($data['Sl_No']);
                    echo $total;
                    }
                    }
                    ?>

                    Topal quantity : <?php echo totalOrders();?>
                    But displaying nothing. Whats wrong with query?

                      Write a Reply...