CodeIgniter Select Query with Multiple Clause Example

CodeIgniter Select Query with Multiple Clause Example

In this tutorial guide, we would love to share with how to use multiple clause with select query in Codeigniter projects.

CodeIgniter provides functions to read, create, update, delete data from the database, and get selected data using multiple where clauses.

Here are some query functions that allow users to get data from a database with and without multiple WHERE clauses:

1. query() Function

The “$this->db->query(“sql query”)” function will allow users to query the database to perform read, update, create and delete operations on the database.

$query = $this->db->query("select * from users");

2. get() Clause

The “$this-> db->get(‘users’);” function will allow users to query the database to get all rows from table:

$query = $this-> db->get('users');

3. select() Clause

The “$this-> db->select(‘*’);” function will allow users to query the database to specific column or all columns from table:

$this->db->select('name');
$query = $this->db->get('users');

4. Select() with limit() Clause

The select() and limit() functions are used to specify the number of records to be retrieved from the database.

$this->db->select('id,name');
$this->db->limit(10);
$query = $this->db->get('users');

5. from() with Select() Clause

The FROM function allows users to specify the name of the table the user wants to get data from the DB table:

$this->db->select('id,name');
$this->db->from('users');
$query = $this->db->get();

6. where() with Select() Clause

The WHERE() clause function allows users to filter and retrieve data from a table:

$this->db->select('id,name');
$this->db->from('users');
$this->db->where('id',5)
$query = $this->db->get();

7. Select Query with Multiple Where Clause Condition

To use multiple where conditions in select query, you can use the like the following:

$this->db->where('Age', 25);
$this->db->where('Name','Developer')
$query = $this->db->get('Users');

Recommended Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

One reply to CodeIgniter Select Query with Multiple Clause Example

  1. good job

Leave a Reply

Your email address will not be published. Required fields are marked *