0

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')");

?>

Edited by titos97: spelling

2
Contributors
3
Replies
16
Views
3 Years
Discussion Span
Last Post by titos97
0

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

0

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

1

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;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.