Welcome Guest, Not a member yet? Register   Sign In
How to return single result from database
#6

[eluser]Thorpe Obazee[/eluser]
Code:
// model
function get_dollars_by_month ($month, $donator_co)
    {
        $query = $this->db->query("SELECT SUM( dollars )
        AS thesum FROM fh_financial_donations
        WHERE MONTH( date ) = MONTH( DATE_SUB( CURDATE( ) , INTERVAL ".$month."
        MONTH ) ) AND donator_co = ".$donator_co."");
        return ($query->num_rows()) ? $query->row() : FALSE
    }

//Controller

$data = $this->yourmodel->get_dollars_by_month($month, $donator_co);

echo $data->thesum;

or you can do this:

Code:
// model
function get_dollars_by_month ($month, $donator_co)
    {
        $query = $this->db->query("SELECT SUM( dollars )
        AS thesum FROM fh_financial_donations
        WHERE MONTH( date ) = MONTH( DATE_SUB( CURDATE( ) , INTERVAL ".$month."
        MONTH ) ) AND donator_co = ".$donator_co."");
        return ($query->num_rows()) ? $query->row()->thesum : FALSE
    }

//Controller

$thesum = $this->yourmodel->get_dollars_by_month($month, $donator_co);

echo $thesum;


Messages In This Thread
How to return single result from database - by El Forum - 05-19-2009, 05:34 PM
How to return single result from database - by El Forum - 05-19-2009, 05:59 PM
How to return single result from database - by El Forum - 05-19-2009, 06:05 PM
How to return single result from database - by El Forum - 05-19-2009, 07:13 PM
How to return single result from database - by El Forum - 05-19-2009, 08:42 PM
How to return single result from database - by El Forum - 05-19-2009, 09:04 PM
How to return single result from database - by El Forum - 05-19-2009, 09:22 PM
How to return single result from database - by El Forum - 05-19-2009, 09:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB