Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

Get the total amount and store it on another table. (Codeigniter)

my target is to total all the (commtype = IN) betAmount only and store it on my "comCurrentBalance" users table. Then, with my SQL update it'll be subtracted the user input's amount to the total value of betAmount from "agent_commmission_history" table. I provided a screenshot below for my problem and my target. Any help will be appreciated.

enter image description here

Controller:

public function comm($userID=0) {
        
        $this->commissions->commOut($userID);

        redirect(base_url() . "commission/commi");
    }

Model:

function commOut($data) {
        
        
        
        $ref= $this->session->userdata('uid') + date ('his');
        $id = $this->session->userdata('uid');
        
        $data = array(
            'userID' => $id,
            'transactionSource' => 'Commi',
            'refNumber' =>  $ref ,
            'amount' =>$this->input->post("amount"),
            "transType" =>"out",
            
        );
       
        $sqlInsertLedger = "INSERT INTO transaction_ledger (transactionSource, transType, refNumber, userID, amount, currentBalance, previousBalance, remarks, createdBy)
                                select '".$data['transactionSource']."', '".$data['transType']."', '".$data['refNumber']."', ".$data['userID'].", ".$data['amount'].", sum(TU.currentPoints + ".$data['amount'].") as totalPoints, TU.currentPoints,
                                'funded by agent', '".$this->session->userdata('uid')."'
                                from users TU where TU.userID=?";
        
        $Q = $this->db->query($sqlInsertLedger, $data['userID']);
        
        //update user table
        
        $sqlUpdate = "update users set  commCurrentBalance = commCurrentBalance - ?, currentPoints = currentPoints + ? where userID = ?"; // ***Current points is already adding and comCurrentBalance is subtracting based on user's input. However, my target is to total the betamount before subtracting happens.*****
        $Q = $this->db->query($sqlUpdate, array($data['amount'], $data['amount'], $data['userID']));
        
   
    }
question from:https://stackoverflow.com/questions/66058320/get-the-total-amount-and-store-it-on-another-table-codeigniter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...