CodeIgniter Forums
missing data from database query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: missing data from database query (/showthread.php?tid=22427)



missing data from database query - El Forum - 09-09-2009

[eluser]richzilla[/eluser]
Hi all. Im having a few problems retrieving data from an mysql database. According to the Codeigniter documentation the result() method reuturnsa an array of objects, so in my example, this function from my model should return an array of objects.

Code:
function get_client_issues($id)
    {
        $this->db->where('issueClientId',$id);
        $query = $this->db->get('issues');
        
        if ($query->num_rows() > 0)
        {
            return $query->result();
        }
        else
        {
            return FALSE;
        }
    }

however when i try to access this array in the controller with this method:

Code:
function Index()
    {
        $res = $this->issue_model->get_client_issues($this->session->userdata('userid'));
        if ($res != FALSE)
        {
            $this->_show('clients/clients_view', $res);
        }
        else
        {
            $this->_show('clients/clients_view');
        }
        
    }

i get an error from the view that calls this, saying that im trying to get the property of a non object. I cant see anywhere that could be causing any problems, however i wondered if anyoen else could spot where ive gone wrong. Just to fill in the blanks, the part of the view thats raising the error is:

Code:
<?php foreach ($data as $issue) : ?>
                
                        <tr>
                        <td class="wide">&lt;?php echo $issue->issueId; ?&gt;</td>
                        <td class="wide">&lt;?php echo $issue->issueOpened; ?&gt;</td>

                        </tr>
                    &lt;? endforeach; ?&gt;

and my _show method:

Code:
function _show($page, $data)
    {
        $this->load->view('global_header');
        $this->load->view($page, $data['data']);
        $this->load->view('global_footer');
    }

any help would be appreciates. Thanks


missing data from database query - El Forum - 09-09-2009

[eluser]n0xie[/eluser]
Code:
function _show($page, $result)
    {
        $data['data'] = $result;
        $this->load->view('global_header');
        $this->load->view($page, $data);
        $this->load->view('global_footer');
    }
Try this