Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

mysql - Get the sum of a column (Codeigniter)

newbie here. How can I get the total sum of the "amount" column? I tried working on a function but it's not dynamic. It only reads the column of my main account. But when i logged on another account, The total amount is still the same. My target is, how can i make it dynamic based on userID? Thank you in advance

enter image description here

Views:

<div class="small-box bg-success">
  <div class="inner">
    <h3><?php echo $tcash;?><sup style="font-size: 20px"> Php</sup></h3>

    <p><b>Total Cash-In</b></p>
  </div>
  <div class="icon">
    <i class="fas fa-coins"></i>
  </div>

Controller:

public function cashout()
{
    $data['activeNav'] = "";
    $data['subnav'] = "ewallets";
    $this->header($data);
    $this->nav();
    

    $data['tcash']=$this->load->ewallets->gettotalcashin();
    
    $this->load->view('cashout', $data);
    
    $this->footer();
}

Model:

function gettotalcashin(){
    
    $this->db->select_sum('amount');
    $result = $this->db->get('cash_out')->row();
    return $result->amount;
}

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

1 Reply

0 votes
by (71.8m points)

Solved already.

Model:

function gettotalcashin(){
    $reqamount= $this->session->userdata('username');
        
    $this->db->select_sum('amount');
    $this->db->where('userID',$reqamount);
    $result = $this->db->get('cash_in')->row();
        
    return $result->amount;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...