2011-10-02 81 views
0

即時通訊功能,將顯示購買和出售清單。我試圖在一個頁面中顯示這兩個。 即時通訊從2個不同的表中獲取值,我想通過這兩個值到相同的模板從2個表格傳遞值到一個視圖codeigniter

有人可以請建議如何做到這一點?

控制器

function leads(){ 
    $this->load->model('listings'); 

    $data['mylists']=$this->member_functions->mine(); 
    $data['mylists2']=$this->member_functions->mine(); 

    $data['heading']='headings/heading_view'; 
    $data['body']='listbody'; 
    $data['nav']='right'; 

    $this->load->view('includes/template',$data); 

} 

型號

function mine(){ 

    $mylists=$this->db->get('buy'); 

    if ($mylists->num_rows()>0){ 

     foreach ($mylists->result() as $a) 
     { 

      $data[]=$a; 

     } 
     return $data; 
    } 

    $mylists2=$this->db->get('sell'); 

    if ($mylists2->num_rows>0) 
    { 
     foreach ($mylists->result() as $b) 
     { 
      $data[]=$b; 

     } 

     return $data; 

    } 

} 

查看

<h2>Buy leads</h2> 
       <?php foreach ($mylists as $mylist):?> 
     <p><?php echo "$mylist->type1 in $mylist->country as $mylist->buyid" ?></p> 

     <?php endforeach;?> 
      </div> 
     <br /> 
      <h2>Sell leads</h2> 
      <?php foreach ($mylists2 as $mylist2):?> 
     <p><?php echo "$mylist2->type1 in $mylist2->country" ?></p> 

     <?php endforeach;?> 

回答

1

不能使用2個return語句withi n是同一個函數,因爲每當遇到第一個函數時......函數返回並停在那裏。嘗試返回單個陣列與2分的結果相反,如:

型號:

function mine(){ 

    $mylists=$this->db->get('buy'); 

    if ($mylists->num_rows()>0){ 

     foreach ($mylists->result() as $a) 
     { 
      $data['res1'][]=$a; 
     } 
    } 

    $mylists2=$this->db->get('sell'); 

    if ($mylists2->num_rows>0) 
    { 
     foreach ($mylists->result() as $b) 
     { 
      $data['res2'][]=$b; 
     } 
    } 
    return $data; 
} 

控制器:

$data['lists']=$this->member_functions->mine(); 

在視圖,該陣列應該被稱爲像$lists['res1']$lists['res2']

相關問題