-3

How to change the following query with the help of query builder codeigniter?

$query=$this->db->query("select a.*,b.nama from transaksi a,
                                    anggota b
                                    where a.no_transaksi='$nomor' and a.no_transaksi
                                    not in(select no_transaksi from pengembalian)
                                    and a.nomor_anggota=b.nomor_anggota");

Note: just want to know another way

riang_a
  • 15
  • 4

1 Answers1

0

Try this:

$this->db->select('a.*, b.nama');
$this->db->from('transaksi a, anggota b');
$this->db->where('a.no_transaksi', $nomor);
$this->db->where('`a.no_transaksi` NOT IN (SELECT `no_transaksi` FROM `pengembalian`)', NULL, FALSE);
$this->db->where('a.nomor_anggota = b.nomor_anggota');
$result = $this->db->get()->result();

The ,NULL,FALSE in the where() tells CodeIgniter not to escape the query, which may mess it up.

Source: subquery in codeigniter active record

Vince
  • 1,133
  • 3
  • 17
  • 34