Fun query help

#1
[eluser]draconus[/eluser]
I am trying to make a basic check register program as a proof of concept to myself to further my skills. Basically, there is a form that submits the newest transaction, and right before the insert the database needs to give me the account balance from the last transaction, then add or subtract the current form post to generate the new balance.

Here is my controller for the form submit:
Code:
function transaction()
    {
        if(isset($_POST['submit']))
        {
            unset($_POST['submit']);
            $_POST['date'] = date("Y-m-d");
            $this->db->select_max('id');
            $query = $this->db->get('transactions');
            $row = $query->row();
            $query = $this->db->get_where('transactions', array('id' => $row->id));
            $row = $query->row();
            $_Post['balance'] = $row->balance + $_Post['credit'] - $_Post['debit'] - $_Post['fees'];
            
            $this->db->insert('transactions', $_POST);
            redirect('budget/');
        }else{
            $this->load->view('transaction');
        }        
    }

it ends up with the balance inserted always being empty. First off, is there a way to wrap these queries into a transaction to save on database requests, also, is there a way to make this function actually work?

I can't seem to figure it out. Any help would be appreciated.

Thanks


Messages In This Thread
Fun query help - by El Forum - 06-15-2010, 11:35 AM
Fun query help - by El Forum - 06-15-2010, 11:41 AM
Fun query help - by El Forum - 06-15-2010, 09:16 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.