mysql - CodeIgniter PHP Combing all rows in Database to display one value -


i'm looking help, i'm looking show numeric value combination of table looks this

finplanincomeid (pk) financialplanid (fk) weekly (int) fortnightly (int) monthly (int) 

i want rows of weekly fortnightly , monthly add make master value have done far this.

model.php

    public function getincome($data) {                  $condition = "debt.[debtid] = '".$data."' , ";         $condition .= "fp.[financialplanid] = fpi.[financialplanid] , ";     $condition .= "debt.[debtid] = fp.[debtid] , ";     $condition .= "fp.[active] = 1 , ";     $condition .= "debt.[clientid] in (select [client_id] [clientportal].[dbo].[ci_user_access] [user_id] = '".$this->session->userdata['logged_in']['id']."')";       $this->db->select ('fp.[debtid], fp.[active], fpi.[financialplanid], fpi.[weekly], fpi.[fortnightly], fpi.[monthly], fpi.[weekly]*4 totalweekly, fpi.[monthly] totalmonthly, fpi.[fortnightly]*2 totalfortnightly');     $this->db->from('[focus].[dbo].[finplanincome] fpi');     $this->db->join('[focus].[dbo].[financialplan] fp', 'fp.[financialplanid] = fpi.[financialplanid]');     $this->db->join('[focus].[dbo].[debt] debt', 'fp.[debtid] = debt.[debtid]');     $this->db->where($condition);     $query = $this->db->get();      return $query->result_array();             } 

controller.php

   public function overview()     {       if($this->_core())     {         $income = $this->accounts_database->getincome($this->session->userdata('debtid'));          $data = array(             'income1'       => $income[0]['totalmonthly'],             'income2'       => $income[0]['totalfortnightly'],             'income3'       => $income[0]['totalweekly']             );          $this->load->view('account_overview_view',$data);      } } 

view.php

<td>income: <?php  $total = $income1 + $income2 + $income3; print($total); ?> </td> 

ive tried cut done of code show parts matter. in nutshell trying take rows of weekly, fortnightly , monthly , combine them master table $total on view display value, have there works adds first row , doesn't rest.

any great.

edit: working sql

select        isnull((sum (isnull(fpi.weekly, 0)) * 4) + sum (isnull(fpi.monthly, 0)) + (sum (isnull(fpi.fortnightly, 0)) * 2), 0)  financialplan fp inner join dbo.finplanincome fpi      on fp.financialplanid = fpi.financialplanid debtid = 1 , active = 1` 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -