Codeigniter gets data using where_not_in

this is what I'm trying to achieve with me two delivery and payment tables

Payment table

Delivery table

so I want to display data that is not in the payment table, but exist in the delivery table, since you can see that the payment table has [del_id] 2 and 3. therefore I try to get [delivery_id] 1. but some of them also retrieving [delivery_id] 2.

here is the model code

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

and controller

public function status(){


        $data['mixs'] = $this->time_model->noPayment_tables();


          $data['main_view'] = "status_view";
            $this->load->view('header', $data);

 }

and browse

<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>

and current result enter image description here

+4
source share
2 answers
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();

}

0
source

, . , var_dump row, , , - ( ):

array
    'del_id' => string '3' (length=1)

, , , , :

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

.

0

Source: https://habr.com/ru/post/1693242/


All Articles