• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help about query

[eluser]Wondering Coder[/eluser]
I like the part of CI active record where I can have a dynamic where clause using get_where().
My controller
$cond = array('user_id'=>1,'data_id'=>2)

My model
function get_logged_user($data)
        $this->db->select('user_id, data_id, coor_id, image');
        $query = $this->db->get_where('users',$data);
        return $query;

but now I'm using a subquery and since CI active record doesn't support subquery, I write my query like this below.
function get_logged_user($userid,$dataid)
        $query = $this->db->query("SELECT user_id, data_id, coor_id, image FROM (
                                   SELECT ad_userid user_id, ad_dataid data_id, '' coor_id, image FROM pps_admin_users
                                   SELECT user_id, data_id, coor_id, image FROM pps_users) b
                                   WHERE b.user_id=$userid AND b.data_id=$dataid",FALSE);
        return $query;
but now my problem is how can I have the same functionality in get_where without using CI active. coz I'll be using again this query but with different where clause. Anyone have an idea here?

make your query by a string you plug in:

$sql = "blah blah blah";
$query = $this->db->query($sql);

[eluser]Wondering Coder[/eluser]
thanks for replying jmadsen,

I don't think that's what I'm looking for. I want a dynamic where clause just like using get_where but can't use CI active record though coz of my subquery.

I would either extend the database class or create a helper function using the code that active record uses to put together WHERE statements.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.