CodeIgniter ActiveRecord question

26 views
Skip to first unread message

Peter Karunyu

unread,
Apr 4, 2013, 5:08:12 AM4/4/13
to codeigni...@googlegroups.com
Suppose I have a tasks table which contains tasks created by several people and where each task can be assigned to any other user,
and the columns like these:

status - A string value, can be Open, In Progress or Closed
created_by - int value, stores the id of the user who created the task
assigned_to - int value, stores the id of the user assigned to a task

And I want to see only open tasks created by or assigned to me, i.e. the query:

SELECT * FROM tasks WHERE status = 'Open' AND (created_by = 3 OR assigned_to = 3)

How can I do this using CodeIgniter ActiveRecord?

Isaak Mogetutu

unread,
Apr 5, 2013, 1:16:21 PM4/5/13
to codeigni...@googlegroups.com
I bet you figured it out by now.

$where = "status='Open' AND created_by=3 OR assigned_to=3";

$this->db->where($where);
$this->db->get('tasks');

Peter Karunyu

unread,
May 13, 2013, 1:24:14 PM5/13/13
to codeigni...@googlegroups.com
Hmmm, didn't know that I could do that. I had already concluded that AR can produce bracketed where clauses, thanks for removing that nail on its coffin :-)


--
You received this message because you are subscribed to the Google Groups "CodeIgniter Kenya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codeigniter-ke...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Regards,
Peter Karunyu
-------------------

Juma Ochola

unread,
May 22, 2013, 12:02:51 PM5/22/13
to codeigni...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages