Welcome Guest, Not a member yet? Register   Sign In
help with query
#1

[eluser]Fenix[/eluser]
I am trying to pull records from a database and pass the results from a model into a controller. what is the best way to do this? i know i am doing this wrong right now so if somebody could point me in the right direction, that would be great.

my model (there is a field in the database for each of the items in the array):
Code:
function get_assets()
    {
        $this->db->select('*');
        $Q = $this->db->get('assets');
        if($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $assets = array
                (
                'asset_id'     => $row['asset_id'],
                'file_name'      => $row['file_name'],
                'file_type'      => $row['file_type'],
                'file_path'      => $row['file_path'],
                'full_path'      => $row['full_path'],
                'raw_name'      => $row['raw_name'],
                'orig_name'      => $row['orig_name'],
                'file_ext'      => $row['file_ext'],
                'file_size'      => $row['file_size'],
                'is_image'      => $row['is_image'],
                'image_width'      => $row['image_width'],
                'image_height'      => $row['image_height'],
                'image_type'      => $row['image_type'],
                'image_size_str' => $row['image_size_str']
                );
            }
        }
        else
        {
            // no results
        }
        $Q->free_result();
        return $assets;
    }

my controller:
Code:
function view_assets()
    {
        $this->load->model('assets');
        
        $data['all_assets'] = $this->assets->get_assets();
        
        // Page Data
        $data['page_title'] = $this->config->item('title').': View Assets';
        $data['left_col'] = $this->load->view('admin/anav_view',$data,true);
        $data['center_col'] = $this->load->view('admin/vassets_view',$data,true);
        $this->load->view('template_view',$data);
    }


Messages In This Thread
help with query - by El Forum - 10-27-2008, 09:29 AM
help with query - by El Forum - 10-27-2008, 09:39 AM
help with query - by El Forum - 10-27-2008, 09:48 AM
help with query - by El Forum - 10-27-2008, 09:55 AM
help with query - by El Forum - 10-27-2008, 09:57 AM
help with query - by El Forum - 10-27-2008, 10:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB