Welcome Guest, Not a member yet? Register   Sign In
Where if
#1

Excuse my bad English!
How can i use if statement in where Codeigniter
Reply
#2

Tell us a bit more about the context.
What do you want to do, and for what do you need where and if?
Reply
#3

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB