Welcome Guest, Not a member yet? Register   Sign In
Returns result from DB even though it's empty!

function index()
        $data['title'] = "Fabriken Fredag | Bildgalleri";

        $config['base_url'] = site_url('/galleri/index/');
        $config['total_rows'] = $this->db->count_all_results('albums');
        $config['per_page'] = 4;
        $config['uri_segment'] = 3;
        $config['first_link'] = 'Första';
        $config['last_link'] = 'Sista';
                //Doesn't matter which one on of $data['albums'] i'm chosing.
        $data['albums'] = $this->db->get('albums');
        //$data['albums'] = $this->galleryModel->All($config['per_page'], $this->uri->segment(3));
        $this->load->view('galleri_view', $data);    

<?php if(empty($albums)): echo "Empty! :S"; ?>
        <?php else: ?>
            &lt;?php foreach($albums->result() as $row): ?&gt;
                &lt;?php echo $row->title; ?&gt;<br />
            &lt;?php endforeach; ?&gt;
        &lt;?php endif; ?&gt;

If I do a var_dump($albums) the result is:
Quote:object(CI_DB_mysql_result)#18 (7) { ["conn_id"]=> resource(30) of type (mysql link persistent) ["result_id"]=> resource(40) of type (mysql result) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(0) ["row_data"]=> NULL }

Don't check empty. In the manual the examples show checking num_rows(). So try checking $albums->num_rows().

Thanks! It's weird that the exact same code, but in other controllers and views files worked as I wanted.

Theme © iAndrew 2016 - Forum software by © MyBB