2012-10-11 53 views
0

型號

$id = $this->session->userdata('id'); 

    $q = $this->db->get_where('shipping_address', array('customer_id' => $id)); 

    if ($q->num_rows == 0) 
    { 
     $data['id'] = 'You dont have a shipping address saved.'; 

    } else { 
     foreach ($q->result() as $row) 
      { 
      $data['first'] = $row->firstname; 
      $data['last'] = $row->lastname; 
      } 
    } 
    return $data; 

控制器

$this->load->model('Customer_accounts'); 

     $customer = $this->Customer_accounts->get_customer_info(); 
     $ship = $this->Customer_accounts->shipping_address(); 

     $data = $ship + $customer; 

    $this->load->view('account_dashboard/personal_information', $data); 

查看

<?php foreach ($ship as $row) : ?> 
    <table class="fixCap" border="0" cellspacing="0" cellpadding="0"> 
     <tr> 
     <td><?php echo $row['firstname'] . $row['lastname']; ?></td> 
     </tr> 

      . . . 

     </tr> 
    </table> 
<?php endforeach; ?>  

的var_dump

僅顯示與1的array t能夠rows但應顯示傳遞所有DB dataforeach我究竟做錯了其中包含的定義customer_idDB查詢沒有得到所有記錄定義

問題

無法兩行?

回答

0

的問題是在我的Model我取代了上面的代碼與

型號

return $this->db->get_where('shipping_address', array('customer_id' => $id))->result(); 

在我

查看

#I echoed the vars as objects 
$row->firstname 
+0

我沒有意識到我的錯誤,直到我張貼了我的問題。無論如何感謝您的幫助。 – fyz

1

使用:

$data = array_merge($ship, $customer); // they will merged as one array 

,或者你可以這樣來做如果u希望他們分開

$data = array(); 
$data['ship'] = $ship; 
$data['customer'] = $customer; 

//In the view 
//ship 
foreach($data['ship'] as $ship) 
{ 
    //Ship values 
} 

//customer 
foreach($data['customer'] as $customer) 
{ 
    //Customer value 
} 

THX

0

你是不是真正從數據庫代碼蒲凌結果。

嘗試這樣的事情

$ret = $q->get()->result(); 

的foreach($ RET爲$行) {

}

相關問題