Welcome Guest, Not a member yet? Register   Sign In
how to create funciton or class or???
#2

[eluser]JoostV[/eluser]
[EDIT] removed a superfluous or_where

Say you do you query in the index() method of your controller. Then you would get this.
Code:
function index() {
    // Set up the dates to query
    $dates = array("2008-11-22", "2008-12-06", "2008-11-30", "2008-11-29", "2008-11-23");
    // Get results
    $data = $this->_date_query($dates)
}

function _date_query($dates) {
    // Query database
    $this->db->select_sum('total','total');
    foreach($dates as $date) {
        // Set a where statement for each date
        $this->db->or_where('date', $date);
    }
    $query = $this->db->get('sale',$sql7);
    
    // Return results
    if($query->num_rows() > 0){
        return $query->result_array();
    }
    else {
        return false;
    }
}

You had best move the _date_query($dates) function to a model, bacause it handels db actions. (remove the underscore from the function name, in that case.)


Messages In This Thread
how to create funciton or class or??? - by El Forum - 12-02-2008, 10:50 PM
how to create funciton or class or??? - by El Forum - 12-02-2008, 11:04 PM
how to create funciton or class or??? - by El Forum - 12-02-2008, 11:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB