gpt4 book ai didi

php - Codeigniter 使用 where_not_in 获取数据

转载 作者:可可西里 更新时间:2023-11-01 07:43:21 26 4
gpt4 key购买 nike

这是我想要达到的目标我有两张 table 交货付款

Payment Table

Delivery Table

所以我想显示不在支付表中但存在于交付表中的数据,如您所见,支付表有 [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();
}

和 Controller

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>

和当前结果 enter image description here

最佳答案

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();

关于php - Codeigniter 使用 where_not_in 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48641053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com