Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

having() Query in Codeigniter

codeigniter mysql
having() Query in Codeigniter

This tutorial shows you how to write having query in codeigniter. This methods permits you to write the HAVING portion of your query. There are 2 possible syntaxes, 1 argument or 2.

Let’s create a having method in codeigniter

$this->db->having('user_id = 20');  // Produces: HAVING user_id = 20
$this->db->having('user_id',  20);  // Produces: HAVING user_id = 20

You can also pass an array of multiple values.

$this->db->having(array('title =' => 'My Title', 'id <' => $id));
// Produces: HAVING title = 'My Title', id < 45

If you are using a database that CodeIgniter escapes queries for, you can prevent escaping content by passing an optional third argument, and setting it to FALSE.

$this->db->having('user_id',  20);  
// Produces: HAVING `user_id` = 20 in some databases such as MySQL
$this->db->having('user_id',  20, FALSE);  
// Produces: HAVING user_id = 20


Identical to having(), only separates multiple clauses with “OR”.


Html code work in comment box

Related Post