I am building a system where it would output the total current balance to the user.
I have a three MySQL tables, first a Members
table where the user data session gets the Member_ID
second is Regular_Savings
and the third (The Out Put Table) Current_Balance
I have the Math formula how to work out the interest (see bellow)
I would like Total_Balance
in Current_Balance
table to use the output the current balance, I was trying to use the query bellow but think I have made a few mistakes.
Query And Codeigniter Model Code
function get_bank()
{
$this->db->SELECT(`Principle` * (POWER((1 + (`Annual_Rate_Interest` DIV `Compound`)),(`Valid_For` * `Compound`)))) +((`monthly_deposit` * (POWER((1 + (`Annual_Rate_Interest` DIV `Compound`)),(`Valid_for` * `Compound`)) -1)) DIV(`Annual_Rate_Interest` DIV `Compound`)) as fav, $this->session->userdata("Member_ID"));
$query = $this->db->get('Regular_Savings');
return $query->result();
}
All help is very much appreciated, Thank You.
****************UPDATE********************
As suggested in a comment, I could use PHP, I the code bellow is close I think, but not right, any ideas ?
Possible PHP solution
<?php
function interest($Principle,$Compound,$Annual_Rate_Intrest,$Valid_For){
$Accumulated=0;
if ($Compound > 1){
$Accumulated=interest($Principle,$Compound-1,$Annual_Rate_Intrest,$Valid_For);
}
$Accumulated += $Principle;
$Accumulated = $Accumulated * pow(1 + $Annual_Rate_Intrest/(100 * $Valid_For),$Valid_For);
return $Accumulated;
}
?>