Q:

How to output codeigniter selects_sum in the view without foreach

How can I output the result of select_sum from controller to the view without using foreach. I don't want to use foreach because my function returns only 1 number. 
The logic is I have a column in DB with numeric values called 'time', I want to sum all of them together, and output the result next to /10000 in my view. 
I believe I need to use row() but I am not sure how.
Controller:
$this->load->library(array('form_validation', 'session'));
    $this->db->select_sum('time');
    $data['num'] = $this->db->get('posts');

    $this->db->order_by('id', 'DESC');
    $data['query'] = $this->db->get('posts');
    $this->load->view('templates/header');
    $this->load->view('templates/navigation');
    $this->load->view('home_page', $data);
    $this->load->view('templates/footer');

View:
<?php foreach ($num->result() as $row): ?>
        <?php if (empty($row->time)): echo "0"?>
        <?php else: echo $row->time ?>
        <?php endif ?>/10000</p>
        <?php endforeach;?>

A:

You can combine row() with the variable.
$sql = $this->db->select_sum('time');
$sql = $this->db->get('posts');
$data['num'] = $sql->row();

And you can call in your view
$num->time;

hope this solve your problem.

