@orpha
In CodeIgniter, the where
and join
methods are used to filter and join the database queries respectively. Here's how you can use them:
1 2 |
$this->db->where('column_name', $value); $this->db->where('column_name !=', $value); // with comparison operators |
You can also use arrays to add multiple WHERE clauses. In such cases, an optional second parameter can be used to negate the WHERE clause. Here's an example:
1 2 |
$where = array('column1' => $value1, 'column2' => $value2); $this->db->where($where); |
1 2 |
$this->db->join('table_name', 'condition', 'join_type'); $this->db->join('table_name', 'condition', 'join_type', $escape); |
Here's an example of joining two tables:
1
|
$this->db->join('users', 'users.id = posts.user_id', 'left'); |
Note: It is recommended to use CodeIgniter's Active Record class rather than writing the raw SQL queries for better security and maintainability.
Hope this helps!