[eluser]jcavard[/eluser]
we're talking basic active record here, you should have the user guide open handy all the time. Anyway
this could be your function in the transaction model
Code:
function get_user_balance()
{
$this->db->select('user_id');
$this->db->select('(SUM(credit) - SUM(debit)) as balance');
$this->db->from('transaction');
$this->db->group_by('user_id');
$handle = $this->db->get();
}
you would call it from your controller this way
Code:
function account()
{
$balances = $this->your_model_name->get_user_balance();
foreach($balances->result() as $row)
{
echo "Balance for user id " . $row->user_id . " is " . sprintf(".2f$", $row->balance) . "$<br />";
}
}
will output this fancy text:
Code:
Balance for user id 4 is 10.00 $
Balance for user id 6 is 75.00 $