Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want two drop down in PHP
one is for selecting school standard
second is for selecting admission year
based on that i need two display result please help for that
I am using PHP , MYSQL , AJAX , Javascript
I have using following code

Javascript code :

C#
<script>
function showUser(str,str1)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","update_new_records_view.php?q="+ str,true);
xmlhttp.send();
}
</script>


and html code is :

XML
<table>
    <tr>
    <td colspan="2">&nbsp;</td><td style="color:red;">Select Current Standard</td>
    <td><select name="select_std"><option selected="selected">Select Division</option>
        <?php
        include('db.php');
        //POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN standard

        $sql = "SELECT * FROM master_std";
        $standards = mysql_query($sql);

        while($row = mysql_fetch_array($standards))
        {
            echo ("<option id='$row[id] 'value='$row[id]'>$row[name_std]</option>");
        }
        ?></select>
        </tr>
    <tr><td colspan="2">&nbsp;</td><td style="color:red;">Select Academic Year</td>
    <td>

    <select name="year" onchange='showUser(this.value)'><option selected="selected">Select Academic Year</option>
        <?php

        include('db.php');
        //POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN standard

        $sql = "SELECT * FROM master_year ORDER BY year_id";
        $category = mysql_query($sql);

        while($row = mysql_fetch_array($category))
        {
            $id=$row['adm_year'];
            echo ("<option id='$row[year_id]' value='$row[year_id]' >$row[adm_year]</option>");
        }
        ?>
        </select></td>
    </tr>
    </table>
Posted
Updated 29-Mar-14 22:10pm
v3
Comments
PrissySC 30-Mar-14 7:34am    
Where is your connection?

http://www.w3schools.com/php/php_mysql_select.asp
EZW 30-Mar-14 21:10pm    
Also just a side-note... MySQL extension (what you're using to access the database) is going to be deprecated in the future and it is recommended to either use MySQLi extension or PDO.

1 solution

This is my code in update_new_records_view.php

XML
<?php
            $q = $_GET['q'];
            //$id =$_REQUEST['a_std'];
            echo "$id";
            require_once "db.php";
/*          $result = mysql_query("SELECT mf.total_fees as fees,tf.payment_dt as pdate,mf.paid_fees as paid,mf.bal as bal,mf.prn_no as prn,ad.student_name as name FROM master_fees mf,admission ad,tran_fees tf WHERE mf.fees_clear='1' and mf.bal='0' and mf.prn_no = ad.prn_no and mf.prn_no = tf.prn_no GROUP BY mf.prn_no");
    */
            $result = mysql_query("SELECT distinct t.prn_no as prn,t.sr_no as srno,a.student_name as sname,ms.name_std as std,t.adm_year as year FROM admission a, tran_allstudents t,master_year m, master_std ms where t.prn_no = a.prn_no and t.adm_year=m.adm_year and m.year_id='$q' and ms.id=t.name_std ");

            echo"<table class='table table-bordered' id='sample_1'>
                <thead>
                <tr>
                    <td id='ff'>GR No</td>
                    <td id='ff'>Sr No</td>
                    <td id='ff'>Student Name</td>
                    <td id='ff'>Standard</td>
                    <td id='ff'>Year</td>
                    <td id='ff'>Status</td>
                </tr>
                </thead>
                ";
            echo "";
            while($row = mysql_fetch_array($result))
            {
                echo"
                <tr>
                    <td align='center'><input type='text' name='grno[]' value='".$row['prn']." 'style='width:70px;height:27px;'disabled/></td>
                    <td align='center'><input type='text' name='grno[]' value='".$row['srno']."'style='width:110px;height:27px;'disabled/></td>
                    <td align='center'><input type='text' name='grno[]' value='".$row['sname']."'style='width:250px;height:27px;'disabled/></td>
                    <td align='center'><input type='text' name='grno[]' value='".$row['std']."'style='width:50px;height:27px;'disabled/></td>
                    <td align='center'><input type='text' name='grno[]' value='".$row['year']."'style='width:90px;height:27px;'disabled/></td>
                    <td align='center'><input type = 'Checkbox' name ='srnocheck[]' value ='<?php echo $row[srno]?>'/></td>
                </tr>";
            }

            echo "</table>";

            //mysql_close($con);
        ?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900