Hello. I need some help in solving a php code project. I have a combo box field (months) that pulls all 12 months from a MYSQL table. The combo box is populated using php. I want to know how can I evaluate the value in the Select tag to do the following.
1) To count the certified, express and/or ground mail for a particular month
2) Storing the mail count in a variable and assign it to a text field <input name="Mcer"....

Here is the code:

<form name="mdropD"> 
                    <select name="months" size="1"> 
                     <?php
					require_once('Connections/WmidsCon.php');
					mysql_select_db($database_WmidsCon, $WmidsCon);
                    $query_monthopt = "SELECT Months FROM tblmonths";
                    $monthopt = mysql_query($query_monthopt, $WmidsCon) or die(mysql_error());
                    $row_monthopt = mysql_fetch_assoc($monthopt);
                    $totalRows_monthopt = mysql_num_rows($monthopt);
										
					do {
					?>
                    <option value="<?php echo $row_monthopt['Months'];?>"
					<?php if(!(strcmp($row_monthopt['Months'],$row_monthopt['Months'])))?>><?php echo $row_monthopt['Months'];?> </option> 
                    <?php
					} while($row_monthopt = mysql_fetch_assoc($monthopt));
					?>  
                    </select> 
                     
           </form> 
            </div></td>
         </tr>
                         
         <tr>
           <td><div align="left">CER:</div></td>
           <td><div align="left"> <input name="Mcer" type="text" id="Mcer" size="10" maxlength="10" readonly="readonly" />
            </div></td>
         </tr>
        <tr>
          <td><div align="left">EXP:</div></td>
          <td><div align="left"> <input name="Mexp" type="text" id="Mexp" size="10" maxlength="10" readonly="readonly" />
            </div></td>
        </tr>
        <tr>
          <td><div align="left">GRD:</div></td>
          <td><div align="left"> <input name="Mgrd" type="text" id="Mgrd" size="10" maxlength="10" readonly="readonly" />
            </div></td>
        </tr>
       </table>

Do you want to get the select value in php after submitting the form, or do you want to change your page the moment the select changes ?

I think you should look into the MySQL COUNT() function. For example

$q = 'SELECT COUNT(id) AS number_of_something
FROM table
WHERE conditions';

This returns a certain count. Hopefully it's what you are looking for ^^.

Do you want to get the select value in php after submitting the form, or do you want to change your page the moment the select changes ?

Yes! Here's the thing. Recently I find out that in order to achieve the combo box evaluation and the total number of certified, express and ground mail (for that particular month) calculation, I have to do two things; 1st - I have to populate the bombo box by extracting the months from MYSQL-months table (this is done the first time I load the page), 2nd - I have to total number of certified, express and ground mail (for that particular month). This is done via javascript which capture the value store in the Select tag by using the id and then reload the page for a 2nd time. Here is the java script:

<script language = "JavaScript">

     function MCert()
     {
          var Result = document.getElementById("mth").value;
          location.href="http://localhost/WMIDSphp/index.php?Result=" + Result; 

     }
</script>

The 2nd time the page is loaded will execute the php code shown below.

<?php 
            echo $_GET['Result'];
            if(isset($_GET['Result']))
            {
            $r = $_GET['Result'];
            $mth_str = substr($r,1,3);
            echo $mth_str; 
            }
            require_once('Connections/WmidsCon.php');
            mysql_select_db($database_WmidsCon, $WmidsCon);
            $query_mcnt = "SELECT COUNT(Rectype) AS Cercnt FROM tblecmts WHERE Rectype='C' ";
            $mcntC = mysql_query($query_mcnt, $WmidsCon) or die(mysql_error());
           ?>
           <input name="Mcer" type="text" id="Mcer" size="10" maxlength="10" readonly="readonly" value="<?php echo $CertMcnt = mysql_result($mcntC,0,0);?>"/>
            </div></td>

This code doesn't work due to an error I'm getting on my $_GET['Result] statement. Don't know why but I'm investigating the error Undefine index. Some how I need to capture the Result value in order to execute my SQL statement. Can you help? Thank you.

Member Avatar for diafol

Use [ CODE ] tags please. Deceptikon did this for you the first time.

I assume you're getting the error on first load, as $_GET does not exist yet. ALso, a dropdown change is a great case for ajax as opposed to js page refresh. Just a thought.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.