ajax php sql填充依赖的组合框

时间:2013-07-19 12:26:08

标签: php ajax

我只是所有这些php ajax事情的初学者。我从数据库中填充了我的一个组合框,但我不能填充第二个。

我需要根据Proses值填充Machine combobox。 最后用Id填写Envanter no。 感谢帮助! 这是我的代码

我的数据库表主

处理|机器| ID
博尔岑| M1 | 1
博尔岑| M2 | 2
博尔岑| M3 | 3
普拉特| M4 | 5
普拉特| M4 | 7个

这是我的代码

<html>
<body>
<div id="content"  style="background-color:#EEEEEE;position:absolute; overflow:hidden; left:138px; top:101px; width:770px; height:450px">
 <form action="" name="myform" id="myform">
  <p><center> MFT1.2 SPC Girisleri Ölcüm Programi</center></p>
    <center><p> Tarih:&nbsp&nbsp <span id="mydate"> </span>
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
    <script type="text/javascript">
    date();
    </script>
    Machine No:
    <select name="Machine">
        <option value="000" selected = "selected"></option>


            </select>           
    </center></p>

    <center><p>
    Vardiya:&nbsp&nbsp
        <select name="Vardiya">
            <option value="000" selected="selected" >
            </option>
            <option>
              1. Vardiya
            </option>
            <option>
              2. Vardiya
            </option>
            <option>
              3. Vardiya
            </option>
        </select>   
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp            
    Envanter No:
    <input type="text" name="envanter" disabled="disabled"/>
    </center></p>
    <center><p>

    Proses:&nbsp&nbsp

            <?php
        // Load field datas into List box

            $cn=mysql_connect("localhost","root","12345678") or die("Note: " . mysql_error());
            $res=mysql_select_db("OlcumTakip",$cn) or die("Note: " . mysql_error());
            $res=mysql_query("select DISTINCT Proses from main;") or die("Note: " . mysql_error());
            ?>
        <select name="Proses">
            <option value="000" selected = "selected"></option> 
        <?php
        while($ri = mysql_fetch_array($res))
        {
        echo "<option value=" .$ri['Proses'] . ">" . $ri['Proses'] . "</option>";
        }
        echo "</select> ";

        mysql_close($cn);
        ?>      

    </center></p>
    <input type="submit" value="Submit" style ="margin-left:350px"/>
 </form>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我建议您使用Jquery来发出ajax请求,这样更容易。要了解进程应该如何,您可以阅读以下帖子中的示例:

http://www.snilesh.com/resources/jquery/jquery-dynamic-selectbox/

http://www.codingcereal.com/2009/09/autopopulate-select-dropdown-box-using-jquery/

我希望导游可以帮到你。