How To Write Subquery In Codeigniter Active Record

Call Now
WhatsApp
Message Now

Details

CodeIgniter Active Records do not currently support sub-queries, However I use the following approach:

 

$this->db->select('id');
$this->db->from('table');
$where_clause = $this->db->_compile_select(false,true);
$this->db->_reset_select();

#Create main query

$this->db->select('*');

$this->db->from('table1');

$this->db->where("`id` NOT IN ($where_clause)", NULL, FALSE);

return $this->db->get('',null,null,true);

 

_compile_select() and _reset_select() are two undocumented (AFAIK) methods which compile the query and return the sql (without running it) and reset the query.

On the main query the FALSE in the where clause tells codeigniter not to escape the query (or add backticks etc) which would mess up the query. (The NULL is simply because the where clause has an optional second parameter we are not using)

However you should be aware as _compile_select() and _reset_select() are not documented methods it is possible that there functionality (or existence) could change in future releases.

The functions _compile_select() and _reset_select() are deprecated.
Instead use get_compiled_select():

 

Related Updates

Payment Gateway Integration Into A Website

In The Online Business Creation Process The First Ideas Are Related To The Business Type, What To Do, What To Sell, And Right There The Question Came Out. How To Charge For Your Services And/or Products? How To Allow Customers To Pay Online Using Their Credit Cards Or Checks? The Answer Couldn't Be Easier; You Need A Merchant Account With The Ability Of Accepting Online Payments Through A Payment Gateway.There Is Where We Can Help You, We Have Hundreds Of Websites Integrated With Almost Any Onl Continue

Send Attachments With PHP Mail()?

To Send An Email With Attachment We Need To Use The Multipart/mixed MIME Type That Specifies That Mixed Types Will Be Included In The Email. Moreover, We Want To Use Multipart/alternative MIME Type To Send Both Plain-text And HTML Version Of The Email.Have A Look At The Example:$filename = 'file'; $path = 'your Path Goes Here'; $file = $path . "/" . $filename;$mailto = 'to@mail.com'; $subject = 'Subject'; $message = 'My Message';$content = File_get_contents($file); $content = Chunk_split(base Continue

Send Email Using PHPMailer And Codeigniter

Send Email Using PHPMailer And CodeigniterCodeIgniter Email Class Built For Handling Double-byte Characters Is Really Bad, Cannot Be Properly Set Up Charest UTF-8.Here We Want To Share Some Information To Use Codeigniter And PHPmailer Together. In This Way, You Can Send Any Type Of Codes In Email Body.We Have To Follow Few Steps To Use PHPmailer With CodeIgniter.1- Download PHPmailer From Original Site. 2- Extract The Downloaded “Zip” File. 3- Open The Extracted File And Copy &ld Continue


Request For Quotation
Location
Shopali Building , Ghandhi Chowk,
Dhrol - 361210
Gujarat (India)
MoTuWeThFrSaSu
Open11:00 AM To 7:00 PM
Ique Infotech
All rights reserved - Copyright © 2024 - Powered by
4allBIZ
Request a Call Back!