我们有2个表user_details
和shipments
我们必须从order_id
表中获取每个用户的所有shipments
,其中shipment_count
表中的user_details
小于或等于4
和onb_status
shipments
表中的!='1'
答案 0 :(得分:0)
您可能想尝试这个。 mysql查询:
选择u.user_email作为电子邮件,s.from_address选自from,s.to_address as to,s.order_id,u.user_id from shipment s left join user_details u on u.user_id = s.user_id其中u.shipment_count< = 4和s.onb_status != 1;
$this->db->select('u.user_email as email, s.from_address as from, s.to_address as to, s.order_id, u.user_id');
$this->db->from('shipments as s');
$this->db->where('u.shipment_count <=', 4);
$this->db->where('s.onb_status !=', 1);
$this->db->join('user_details as u', ' u.user_id = s.user_id');
$query = $this->db->get();
答案 1 :(得分:0)
模型
function get_data(){
$this->db->select('*')
$this->db->from("shipments AS t1");
$this->db->join("user_details AS t2", "t1.user_id = t2.user_id);
$query = $this->db->get();
return $query->result();
if ($query->num_rows() >0){
foreach ($query->result() as $data) {
$results = $data;
}
return $results;
}
控制器
function data()
{
$data['results'] = $this->your model->get_data();
$this->load->view('your view');
}
视图
<table border="2">
<thead>
<th>email</th>
<th>from</th>
<th>to</th>
<th>order_id</th>
<th>order_id</th>
</tr>
</thead>
<tbody>
<?php
foreach ($result as $data) :
?>
<tr>
<td><?php echo $data->email; ?></td>
<td><?php echo $data->from_address; ?></td>
<td><?php echo $data->to_addres; ?></td>
<td><?php echo $data->order_id; ?></td>
<td><?php echo $data->user_id?></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
我希望它有效