Hi Guys , I couldnt dispay sum of a column of sqlite database in php . I tried the sql statement in database its working fine but not sure how to dispay the result in PHP . I belive i need to fetch it and then dispay any help will be appreciate . Thanks in advanced .

Sql statement :

<?PHP 
$dbhandle = new PDO('sqlite:test.sqlite');

$query = $dbhandle->query("SELECT  COALESCE(SUM(Qty) ,0) AS TOTAL FROM RMA where (Status='Returne')");

?>

ididn't understand your problem so this example to get and store the result of your query and then echo the result

$this->db->select('SUM(Total_sale) as Total  from sales where client_id='.$clientid);
                $total=$this->db->get()->result();
                foreach($total as $ci_total)
    {
        $client_money=$ci_total->Total;
    Return $client_money;
    }

i hope this help you

Thanks for your help i tried your way but getting error . What i am trying to get output echo of Total Items

 $this->db->select('(SUM(Qty) AS Total FROM RMA where (Status="Returnee")');
    $total=$this->db->get()->result();
    foreach($total as $ci_total)
    {
    $client_money=$ci_total->Total;
    Return $client_money;
    }

        echo $client_money;

And the error i getting
Fatal error: Using $this when not in object context in

Thanks guys for your help . I sort that out

$dbhandle = new PDO('sqlite:test.sqlite');

$sqlTotal = $dbhandle->prepare("SELECT SUM(Qty) FROM RMA Where (Status='Inwards')");


    $sqlTotal->execute();
    $totalResult = $sqlTotal->fetch(PDO::FETCH_NUM);
    $totalResult = $totalResult[0];

echo  $totalResult;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.