2016-05-12 25 views
2

我正在构建一个网页,使用户能够查看他们选择的特定产品的报告。步骤如下:使PHP函数互相协作

User chooses interface(Beta或Cloud) - >User Chooses Product(产品基于所选接口) - > Info会相应显示。

其中显示的信息写入如下页面:

HTML

<div class="roundiv" > 

     <h4>*Interface: </h4> 
     <select class="form-control " style='width:250px;' onclick="INSERT SOMETHING HERE" > 
      <option value="-1" >Select Interface </option> 
      <?php 
       config::selectInterface($cao); 
      ?> 

     </select> 

     <h4> 
      *Product: 
     </h4> 
     <select class="form-control" style="width:250px;"> 
      <option value="-1" >Select Product</option> 
      <?php 
       config::selectIntProduct($cao); 
      ?> 
     </select> 
     <button class="btn btn-success " value="Submit" onclick="" style="margin-left: auto; display:block;" > Submit </button> 
     <!-------------INFO WILL BE DISPLAYED HERE-------------> 
    </div> 

我已经开始在配置类编写功能,并希望保持这种方法。

这是我的配置类编写的函数:

功能1

public static function selectInterface(CGenDb $cao) { 

    $sel_interface_options = new CGenRS("select type_desc, type_id from lu_type where type_status = 't' and type_group = 'cloud' and type_sub_group = 'db'", $cao); 
    $sel_interface_options->first(); 
    if ($sel_interface_options->rowcount()) { 
     while (!$sel_interface_options->eof()) { 
      echo "<option value='" . $sel_interface_options->valueof('type_id') . "'>" . $sel_interface_options->valueof('type_desc') . "</option>"; 
      $sel_interface_options->next(); 
     } 
    } 
    $interface_bool = True; 
    return $interface_bool; 
} 

和类selectIntProducts会是这个样子:

功能2

public static function selectIntProduct(CGendb $cao,$selected_interface){ 

    $selected_interface=$cao_interface= "The interface ID" 

    $sel_product_options = new CGenRS("select prod_name, prod_id from lu_products where prod_active = 't'", $cao_interface); 
    $sel_product_options->first(); 

      if ($sel_product_options->rowcount()) { 
       while (!$sel_product_options->eof()) { 
        echo "<option value='" . $sel_product_options->valueof('prod_id') . "'>" . $sel_product_options->valueof('prod_name') . "</option>"; 
        $sel_product_options->next(); 
       } 
      } 
} 

这是我需要帮助的:

  1. 我想要显示的产品选择器只有一个接口/选择。(我的想法是从功能1返回$interface_bool,测试,如果这是真的,如果是,显示下一个部分。 )

  2. 在功能选择的值1应该然后在功能2

$selected_interface我怎样才能做到这一点?

回答

0

你只能用php来实现它,当你重新加载页面并发送选定的接口回到php。

更好和更方便的是使用JavaScript来填充选择,为此我建议使用knockout.js。它有很好的文档可以遵循。

对于PHP,我建议这样的:

<div class="roundiv" > 
    <h4>*Interface: </h4> 
    <select class="form-control " style='width:250px;' onchange="document.location.href='https://url-to-same-page&interface=' + this.options[this.selectedIndex].value" > 
     <option value="-1" >Select Interface </option> 
     <?php 
      config::selectInterface($cao, $_GET['interface']); 
     ?> 

    </select> 

<?php if (!empty($_GET['interface'])): ?> 
    <h4> 
     *Product: 
    </h4> 
    <select class="form-control" style="width:250px;"> 
     <option value="-1" >Select Product</option> 
     <?php 
      config::selectIntProduct($cao, $_GET['interface']); 
     ?> 
    </select> 
    <button class="btn btn-success " value="Submit" onclick="" style="margin-left: auto; display:block;" > Submit </button> 
    <!-------------INFO WILL BE DISPLAYED HERE-------------> 

<?php endif; ?> 
</div> 

并更新selectInterface包括选择的接口:

public static function selectInterface(CGenDb $cao, $selected_interface) { 
    // ... code 
    while (!$sel_interface_options->eof()) { 
     echo "<option value='" . $sel_interface_options->valueof('type_id') . "' " 
      . ($selected_interface == $sel_interface_options->valueof('type_id') ? 'selected="selected"' : '') 
      . ">" . $sel_interface_options->valueof('type_desc') . "</option>"; 
     $sel_interface_options->next(); 
    } 
    // .. code continues 
}