2012-09-24 37 views
1

我試圖從控制器發送一個數據庫的所有聯繫人在我的數據庫表「聯繫人」,然後在下拉菜單中顯示他們的數組。接下來是關於這個主題的CodeIgniter文檔http://codeigniter.com/user_guide/general/views.html,但它並不是我想要做的。 這裏是我試圖做的:從控制器發佈一個MySQL數據在CodeIgniter中查看

function getAll_contact(){ 
    $exist= $this->contacts_model->get_all('contacts'); 
    if($exist) 
     { 
      $all_contact = $this->contacts_model->read('contacts'); 
     //echo json_encode($all_contact); prints all the contacts in the table 
        $this->load->view('myView', $contact); 
     } 
    } 

筆者認爲:

 <select class="span4"> 
      <?php if(isset($all_contact) && ! empty($all_contact)){ 
      foreach($all_contact as $contact){ 
      echo "<option value='".$contact->id_contact."'>".$contact->company."</option>"; 


    } 
} 
     </select> 

這不顯示在下拉菜單中任何東西。任何人都可以幫助我嗎?

回答

0

首先,您已經命名變量$ contact而不是$ all_contact。

解決辦法:

function getAll_contact(){ 
    $exist= $this->contacts_model->get_all('contacts'); 
    if($exist) 
    { 
    $data['all_contact'] = $this->contacts_model->read('contacts'); 
    //echo json_encode($data); prints all the contacts in the table 
    $this->load->view('myView', $data); 
    } 
} 

那麼你訪問它就像你目前在你的看法。

2

把烏拉圭回合結果在數據陣列..

$data['all_contact']=$this->contacts_model->read('contacts'); 

併發送陣列查看

$this->load->view('myView', $data); 

,你可以採取的變量在視圖中使用$ all_contact ..likeü目前有..

相關問題