Welcome Guest, Not a member yet? Register   Sign In
Multiple functions for several joins in a query - how to do it?
#2

[eluser]Mischievous[/eluser]
Not sure about what your exactly trying to do but I always setup my DB requests like this:

Code:
function fetch_review($where, $join, $type = 'array')
    {
        $type = strtolower($type);
        if(is_array($where))
        {
             foreach($where as $column => $value)
             {
                 $this->db->where_in($column, $value);
             }
        }
        if(is_array($join))
        {
             foreach($join as $table => $fields)
             {
                 $this->db->join($table, $fields);
             }
        }
        $this->db->join('authors', 'authors.id = movie_review.author');
        $result = $this->db->get('movie_review');
        if($this->db->count_all_results() > 0)
        {
            switch($type)
            {
                case "object":
                    $request = $result->result();
                break;
                case "bool":
                    return TRUE;
                break;
                default:
                    $request = $result->result_array();
            }
            return $request;
        } else {
            return FALSE;
        }
    }
Usage:
Code:
$where = array('id' => $id);
    $join = array('persons' => 'persons.id = movie_review.director_1');
    $this->fetch_review($where, $join);
Which allows you to pass where statements and join statements as you need dynamically?
As for the naming, setup a format_result() function and run through the result and add your prefix's as needed d1_director, d2_director etc. etc.


Messages In This Thread
Multiple functions for several joins in a query - how to do it? - by El Forum - 04-20-2010, 06:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB