2017-10-10 75 views
-2

我试图根据所选员工的值提取相关津贴价格。当我选择一个员工时,会生成津贴类型,但是对于每种津贴类型,回报相同的价格。根据下拉框选择生成的值填充文本字段

allowance price is same in all text fields.

我尝试下面的代码,但找不到错误。你能帮我找到我的代码中的错误?

  <div class="form-group"> 
       <label class="control-label col-lg-4" for="advanceAmount">Allowances: </label> 
       <div class="col-lg-3"> 

        <?php 
          for($i = 0; $i < count($b); $i++){ 
           echo '<input type="text" class="form-control input-sm margin-bottom" name="allowance_type" value="' . $b[$i] . '">'; 
          } 
          ?> 

         </div> 
         <div class="col-lg-3"> 

          <?php 
           $i = 0;        
           $s = mysqli_query($connection,"select * from allowances_payroll where allowance_name = '$b[$i]'"); 

           $r = mysqli_fetch_assoc($s); 

            for($i = 0; $i < count($b); $i++){ 
            echo '<input type="text" class="form-control input-sm margin-bottom" value="' . $r['allowance_amount'] . '">'; 
          } 
          ?> 

         </div> 
        </div> 

$ b是展开数据库中的许可类型。

 if($result1){ 
     while($record = mysqli_fetch_array($result1)){ 
      $empId = $record['emp_id']; 
      $department = $record['dep_name']; 
      $salary = $record['emp_basicSalary']; 
      $designation = $record['emp_classification']; 

      $allowance = $record['allowances_types']; 
      $b = explode(" ,", $allowance);     

     } 
     } 

感谢

回答

0

你在循环放错了地方。 你的代码更改为:

for($i = 0; $i < count($b); $i++){        
    $s = mysqli_query($connection,"select * from allowances_payroll where allowance_name = '{$b[$i]}'"); 

    $r = mysqli_fetch_assoc($s); 

    echo '<input type="text" class="form-control input-sm margin-bottom" value="' . $r['allowance_amount'] . '">'; 
    } 
} 

还要注意{}周围$b[$i]也可以通过其他两个串联等。

+0

非常感谢。它按预期工作。 – lakshi

相关问题