You can just surround your query builder calls with your if statements.
Take a query that gets users that are members and paid:
PHP Code:
$this->db->from('users');
$this->db->where('user_status', 'member');
$this->db->where('user_payment_status', 'paid');
$users = $this->db->get()->result_array();
Now you only want to check for paid if some variable is set, say $show_paid_only is true.
PHP Code:
$this->db->from('users');
$this->db->where('user_status', 'member');
if ($show_paid_only === TRUE) $this->db->where('user_payment_status', 'paid');
$users = $this->db->get()->result_array();
If you are chaining your calls you just break the chain to insert the if statement.