dream752614590 2012-09-24 14:02
浏览 29

从控制器发布一个mysql数据,以便在CodeIgniter中查看

I'm trying to send from a controller to a view an array of all contacts who are in my database table "Contacts" and then display them on a drop down menu.I followed the CodeIgniter documentation about this topic http://codeigniter.com/user_guide/general/views.html but it isn't really what I would like to do. Here is what I tried to do :

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);
        }
    }

In my view :

      <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>

This does not show anything on the drop down menu. Could anyone help me please ?

  • 写回答

2条回答 默认 最新

  • doufan3958 2012-09-24 14:04
    关注

    First of all, you've named the variable $contact instead of $all_contact.

    The solution:

    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);
      }
    }
    

    Then you access it like you are currently in your view.

    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序