Model
$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;
Controller
$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);
View
<?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
Is only showing an
array
with 1 of the the table rows
but it should be showing 2 rows which contain the defined customer_id
Problem
Unable to pass the all the db
data
to the foreach
what am I doing wrong?
use:
$data = array_merge($ship, $customer); // they will merged as one array
or you can do it this way if u want them separated
$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
}
0 comments:
Post a Comment