2015-12-29 79 views
-1

我試圖讓第一個函數中使用的變量$drop_var1轉換爲第二個函數,我需要在查詢中使用SQL。每次我試圖通過爲全局變量或返回黑色或沒有數據的任何其他方法......我真的在失去了如何使這項工作變量和函數

//************************************** 
//  First selection results  // 
//************************************** 

if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
    $return_value = drop_1($_GET['drop_var']); 
} 

function drop_1($drop_var1) 
{ 
$TD_DB_RESOURCE = open_teradata_resource(); 

$result2 = "SELECT DISTINCT a.call_id as id, b.call_name as name FROM call_log as a, call as b WHERE cust_id in ($drop_var1) and src_row_cre_dt between '2015-12-26' and '2015-12-26' and a.call_id = b.call_id"; 
echo $result2."<br>"; 
$arr_results = odbc_exec($TD_DB_RESOURCE, $result2); 

    echo '<select name="drop_2" id="drop_2"> 
      <option value=" " disabled="disabled" selected="selected">Choose API</option>'; 

      while ($drop_2 = odbc_fetch_array($arr_results)) 
      { 
      echo '<option value="'.$drop_2['id'].'">'.$drop_2['name'].'</option>'; 
      } 
    echo '</select><br><br>'; 

    echo "<script type=\"text/javascript\"> 
$('#wait_2').hide(); 
    $('#drop_2').change(function(){ 
     $('#wait_2').show(); 
     $('#result_2').hide(); 
     $.get(\"func.php\", { 
     func: \"drop_2\", 
     drop_var: $('#drop_2').val() 
     }, function(response){ 
     $('#result_2').fadeOut(); 
     setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400); 
     }); 
     return false; 
    }); 
</script>"; 
} 

//************************************** 
//  Second selection results  // 
//************************************** 

if($_GET['func'] == "drop_2" && isset($_GET['func'])) { 
    $return_value = drop_2($_GET['drop_var']); 
} 

function drop_2($drop_var2) 
{ 
    $TD_DB_RESOURCE = open_teradata_resource(); 

$result3 = "SELECT DISTINCT rc FROM call_log WHERE call_id in ('$drop_var2') and src_row_cre_dt between '2015-12-26' and '2015-12-26' and cust_id in ($drop_var1)"; 
echo $result3."<br>"; 
$arr_results = odbc_exec($TD_DB_RESOURCE, $result3); 

    echo '<select name="drop_3" id="drop_3"> 
      <option value=" " disabled="disabled" selected="selected">Choose API Error Code</option>'; 

      while ($drop_3 = odbc_fetch_array($arr_results)) 
      { 
      echo '<option value="'.$drop_3['rc'].'">'.$drop_3['rc'].'</option>'; 
      } 
    echo '</select><br><br>'; 

    echo "<script type=\"text/javascript\"> 
$('#wait_3').hide(); 
    $('#drop_3').change(function(){ 
     $('#wait_3').show(); 
     $('#result_3').hide(); 
     $.get(\"func.php\", { 
     func: \"drop_3\", 
     drop_var: $('#drop_3').val() 
     }, function(response){ 
     $('#result_3').fadeOut(); 
     setTimeout(\"finishAjax_tier_four('result_3', '\"+escape(response)+\"')\", 400); 
     }); 
     return false; 
    }); 
</script>"; 
} 

這裏是查詢的樣子

SELECT DISTINCT a.call_id as id, b.call_name as name FROM call_log as a, call as b WHERE cust_id in ('123456789') and src_row_cre_dt between '2015-12-26' and '2015-12-26' and a.call_id = b.call_id 

SELECT DISTINCT rc FROM call_log WHERE call_id in ('29') and src_row_cre_dt between '2015-12-26' and '2015-12-26' and cust_id in() 

回答

1

這是因爲在調用下面的函數,變量被命名爲$ drop_var2,但在構建你使用$ drop_var1

function drop_2($drop_var2) 
{ 
    $TD_DB_RESOURCE = open_teradata_resource(); 

$result3 = "SELECT DISTINCT rc FROM call_log WHERE call_id in ('$drop_var2') and src_row_cre_dt between '2015-12-26' and '2015-12-26' and cust_id in ($drop_var1)"; 
+0

因爲'm試圖從第一個函數drop_var1裏面第二個函數drop_2 –

0

這是一個非常基本的問題查詢,請consid呃再次閱讀PHP手冊。三種方法來我的心立刻道:

  1. 把它作爲一個參數:function drop_2($drop_var2, $another_variable)
  2. 將兩種功能的一類,使變量類變量:$this->var1
  3. 使變量全球(不好的做法,雖然)。

此外,混合HTML輸出的代碼是從未一個好主意,請考慮使用MVC框架(laravelcodeiginiterSlim)來代替。

+0

我試過了選項1和選項3他們不工作 –