通过匹配 id codeigniter 显示来自两个 table 的数据
display data from two table by matching id codeigniter
客户table
enter image description here
网站产品table
enter image description here
我想显示当前登录用户产品详情的记录
例如:15 号客户已登录,则应仅显示他的记录
型号
public function customerparcelstatus()
{
$this->db->select('*');
$this->db->from('siteproducts');
$this->db->join('customer', 'siteproducts.customer_id=customer.customer_id');
//$this->db->order_by('customer.customer_id');
return $this->db->get()->result_array();
}
控制器
public function custparcelstatus()
{
$this->load->model('orbitcustomer_model');
$data['parcellistview'] = $this->orbitcustomer_model->customerparcelstatus();
$this->load->view('customer/customer_dashboard', $data);
}
查看
<tbody>
<?php if (!empty($parcellistview)) { foreach($parcellistview as $user) {?>
<tr>
<td><?php echo $user['customer_id']; ?></td>
<td><?php echo $user['customer_code']; ?></td>
<td><?php echo $user['product_code']; ?></td>
<td><?php echo $user['received_date']; ?></td>
<td><?php echo $user['received_from']; ?></td>
<td><?php echo $user['tracking_ref_no']; ?></td>
<td><?php echo $user['parcel_status']; ?></td>
<td><?php echo $user['parcel_note']; ?></td>
</tr>
<?php } } else { ?>
<tr>
<td>Norecords Found</td>
</tr>
<?php } ?>
您需要通过在如下查询中使用 where 子句来检索仅与当前登录客户相关的记录。
$this->db->where('customer_id', $customer); //currently logged in user
客户table enter image description here
网站产品table enter image description here
我想显示当前登录用户产品详情的记录
例如:15 号客户已登录,则应仅显示他的记录
型号
public function customerparcelstatus()
{
$this->db->select('*');
$this->db->from('siteproducts');
$this->db->join('customer', 'siteproducts.customer_id=customer.customer_id');
//$this->db->order_by('customer.customer_id');
return $this->db->get()->result_array();
}
控制器
public function custparcelstatus()
{
$this->load->model('orbitcustomer_model');
$data['parcellistview'] = $this->orbitcustomer_model->customerparcelstatus();
$this->load->view('customer/customer_dashboard', $data);
}
查看
<tbody>
<?php if (!empty($parcellistview)) { foreach($parcellistview as $user) {?>
<tr>
<td><?php echo $user['customer_id']; ?></td>
<td><?php echo $user['customer_code']; ?></td>
<td><?php echo $user['product_code']; ?></td>
<td><?php echo $user['received_date']; ?></td>
<td><?php echo $user['received_from']; ?></td>
<td><?php echo $user['tracking_ref_no']; ?></td>
<td><?php echo $user['parcel_status']; ?></td>
<td><?php echo $user['parcel_note']; ?></td>
</tr>
<?php } } else { ?>
<tr>
<td>Norecords Found</td>
</tr>
<?php } ?>
您需要通过在如下查询中使用 where 子句来检索仅与当前登录客户相关的记录。
$this->db->where('customer_id', $customer); //currently logged in user