2012-09-24 38 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ü目前有..

相关问题