这是我想要实现的目标 我有两张桌子 投放和付款
所以我想显示不在付款表中但存在于交货表中的数据,因为您可以看到付款表有[del_id] 2和3。所以我试图获取[delivery_id] 1.但有些如何获取[delivery_id] 2.
这是型号代码
public function noPayment_tables(){
$query = $this->db->query('SELECT del_id FROM payments');
foreach ($query->result_array() as $row)
{
echo $row['del_id'];
}
$this->db->select('*');
$this->db->from('delivery');
$this->db->where_not_in('delivery_id', $row);
return $this->db->get()->result();
}
和控制器
public function status(){
$data['mixs'] = $this->time_model->noPayment_tables();
$data['main_view'] = "status_view";
$this->load->view('header', $data);
}
并查看
<table class="table">
<thead>
<tr>
<th>consignee</th>
<th>airway id</th>
<th>status</th>
</tr>
</thead>
<tbody>
<?php foreach ($mixs as $ta): ?>
<tr>
<td><?php echo $ta->consignee ?></td>
<td><?php echo $ta->airway_id ?></td>
<td><?php echo $ta->delivery_id ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
答案 0 :(得分:0)
我相信你需要一行才能成为一个简单的数组。在你的情况下,如果你var_dump
行,你可能会看到类似的东西(因为你在每个循环上都取代它的值):
array
'del_id' => string '3' (length=1)
您需要做的是,在迭代的每一行上获取每个ID并将这些键存储在单独的数组中,如下所示:
$query = $this->db->query('SELECT del_id FROM payments');
$deleted = [];
foreach ($query->result_array() as $row)
{
echo $row['del_id'];
$deleted = $row['del_id'];
}
$this->db->select('*');
$this->db->from('delivery');
$this->db->where_not_in('delivery_id', $deleted);
return $this->db->get()->result();
这应该有用。
答案 1 :(得分:0)
public function noPayment_tables(){
$query = $this->db->query('SELECT del_id FROM payments');
$array=array();
foreach ($query->result_array() as $row)
{
array_push($array,$row['del_id']);
}
$this->db->select('*');
$this->db->from('delivery');
$this->db->where_not_in('delivery_id', $array); //need to pass array
return $this->db->get()->result();
}