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');
good job