Reputation: 3823
I am using Kohana framework 3, and I need to create a query
I need add one where part only if variable is true, otherwise I don't need one WHERE part.
How add php if script in query?
What I need:
ORM::factory('test')
->select( array('name', 'surname') )
->where('id', '=', $user->id)
if ($active == 1) {
->where('status', '=', 1)
}
->order_by('docid', 'DESC')->find_all();
Upvotes: 0
Views: 54
Reputation: 17725
$query = ORM::factory('test')
->select( array('name', 'surname') )
->where('id', '=', $user->id);
if ($active == 1) {
query->where('status', '=', 1);
}
$query->order_by('docid', 'DESC')->find_all();
Upvotes: 1