Javascript-将值从下拉列表传递到PHP查询

时间:2018-10-18 15:32:36

标签: javascript php html angularjs-ng-repeat

嘿:我正在尝试将一个下拉列表中的值传递给选择查询($ sel_query)。数据库是MySQL,我正在使用WAMP。基本上,代码应该像这样工作:

  • 表格选择器下拉菜单:选择一个表格
  • 字段选择器下拉列表:在表格下拉列表中选择的表格中所有字段的列表

代码如下:

表选择器:

<select id="pt-{{$index}}" name="pt-{{$index}}"  ng-model="parentTable" type="selectable">
    <option style="display:none" value="default" ng-model="values[$index]">select a table</option>
    <?php
    $count=1;
    $sel_query="SHOW TABLES";
    $result = mysqli_query($con,$sel_query);
    while($row = mysqli_fetch_assoc($result)) { ?>
        <option ng-model="values[$index]" value="<?php echo $row["Tables_in_golddb"]; ?>"><?php echo $row["Tables_in_golddb"]; ?></option>
    <?php $count++; } ?>
</select>

字段选择器:

<select id="pf-{{$index}}" name="pf-{{$index}}"  ng-model="parentField" type="selectable">
    <option style="display:none" value="">select a field</option>
    <?php
    $count=1;
    $sel_query="select * from information_schema.columns where table_name = 'assets' and table_schema = 'golddb'";
    $result = mysqli_query($con,$sel_query);
    while($row = mysqli_fetch_assoc($result)) { ?>
        <option value="<?php echo $row["COLUMN_NAME"]; ?>"><?php echo $row["COLUMN_NAME"]; ?></option>
    <?php $count++; } ?>
</select>

我要这样做,以便字段选择器中的查询($ sel_query)是动态的,基于表选择器中选择的值(当前为“资产”)。最终产品将能够基于一系列构建查询的下拉列表中的选择来创建报告。

0 个答案:

没有答案
相关问题