2012-11-19 24 views
-1

我面臨幾個問題提供的foreach無效參數 - 創建一個功能等消息:笨的應用過程中笨

function searchUnivtab() { 
     $country = $this->input->post('countryKey'); 
     $state = $this->input->post('stateKey'); 
     $level = $this->input->post('level'); 
     $degType = $this->input->post('degType');  
     $country = str_replace('%20', ' ', $country); 
     $state = str_replace('%20', ' ', $state); 
     $degType = explode('~', $degType); 
     $data = @$this->get->getSearchedUniversityTab($country, $state, $level, $degType[1]); 
     $html = ''; 
     $i = 0; 
     foreach($data as $d) 
     { 
      $html .= '<option value="'.$d['name'].'">'.$d['name'].'</option>'; 
     } 
     echo $html; die; 
    } 

錯誤爲:A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()Line Number: 270其在 foreach

任何與上述代碼有關的幫助?在下面的行

+1

你確定更換

$data = @$this->get->getSearchedUniversityTab($country, $state, $level, $degType[1]); 

的$數據數組(我沒有使用codeigniter)? –

+0

@NullPointer No sir,它不是數組,Print'數據不是數組'。 –

+0

Okie,如果我刪除了,我如何獲取$ data的值?任何幫助?代碼與上面相同 - –

回答

-1
function getSearchUniversity() { 
    country = jQuery('[name=countryKey]').val(); 
    state = jQuery('[name=stateKey]').val(); 
    level= jQuery('[name=level]').val(); 
    degType= jQuery('[name=degType]').val(); 
    jQuery.ajax({ 
    type: "POST", 
    url:baseurl+ 'welcome/searchUnivtab', 
    cache: false, 
    data: {countryKey: country, stateKey: state, level: level, degType: degType}, 
    error: function() 
    { 
     //notify('Error: Your request could be processed.. try again..!!'); 
    }, 
    success: function(html) 
    { 
     jQuery('[name=universityList]').html(html); 
     return false; 
    } 
    }); 
} 
1

刪除@,看它是否產生任何錯誤 所以用

$data = $this->get->getSearchedUniversityTab($country, $state, $level, $degType[1]); 
+0

謝謝你這麼多,其工作,但錯誤已更改爲消息:未定義的偏移量:1 –

+0

所以你的錯誤基本上是別的地方。郵政領域degType期待一個使用〜爆炸的值,你發佈的值是多少? – xelber

+0

它顯示在第267行,$ data = $ this-> get-> getSearchedUniversityTab($ country,$ state,$ level,$ degType [1]); –

0
if(is_array($data)) { 
    foreach($data as $d){ 
     $html .= '<option value="'.$d['name'].'">'.$d['name'].'</option>'; 
    } 
} else { 
    echo 'data is not an array.'; 
}