根据另一个选择框中的选择填充选择框 [英] Populating a select box based upon a selection from another select box

查看:84
本文介绍了根据另一个选择框中的选择填充选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<select id="categoriesSelect" class="e1">
<option value="0">Please select a category you wish to view!</option>

        <?php
        $con = mysqli_connect(,,,,);
        // Check connection
        if (mysqli_connect_errno())
           {
           echo "<option>Failed to connect to MySQLi</option>" ;
           }
         $result = mysqli_query($con,"SELECT * FROM Category");
         while($row = mysqli_fetch_array($result)) {
          echo "<option value='".$row['Category']."'>".$row['Category']."</option>";
          }
         mysqli_free_result($result);
         mysqli_close($con);
        ?>





到目前为止,这就是我的全部内容有:



我需要根据第一个框中的类别选择从业务表中填充业务名称(Bname)。有人可以帮我创建一个javascript函数来执行此操作。



注意:php部分需要保持尽可能接近当前格式,除非使用连接代码,否则我的服务器将无法连接到数据库。 />


数据库方案如下:



So far this is all I have:

I need populate the business name (Bname) from the business table based upon the category selection from the first box. Can someone help me create a javascript function that will do this.

Note: The php portion needs to stay as close to its current format as possible, my server will not connect to the database unless that connection code is used.

The database scheme is as follows:

Category -Table
   Category -Column (Primary Key)

Business -Table
   Bname -Column (Primary Key)
   Category -Column Foreign Key referencing Category table





我需要类似的东西:

点击这里查看图片

推荐答案

con = mysqli_connect(,,,,);
// 检查连接
if (mysqli_connect_errno())
{
echo < span class =code-string>< option>无法连接到MySQLi< / option>;
}
con = mysqli_connect(,,,,); // Check connection if (mysqli_connect_errno()) { echo "<option>Failed to connect to MySQLi</option>" ; }


result = mysqli_query(
result = mysqli_query(


con , SELECT * FROM Category);
while(
con,"SELECT * FROM Category"); while(


这篇关于根据另一个选择框中的选择填充选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆