codeigniter中的非对象的未定义变量和属性

I'm getting these two error messages for my 3 variables:

message 1) Undefined variable: rows message 2) Trying to get property of non-object

EDIT: (finally found the edit button), so the 3 variables are:

        $anatomic_code = $rows->NerveCode;
        $ProxAccess = $rows->ProxAccess;
        $DistAccess = $rows->DistAccess;

Which can be found in my view, it is the above 3 lines that are giving me the two errors.

I have not included the model as I don't think the problem is there, and more so because its quite some code due to the developers before me has used lots of different tables storing the data in... however I'm ready to post it if needed.

Controller ->

function se_enkel_test()
    {
    $this->freakauth_light->check('submitter');
    $tech_num = $this->uri->segment(6);
    $this->load->model('view_single_test','',true);
    $data['query'] = $this->view_single_test->query();
    $data['query_tech_type'] =  $this->view_single_test->query_tech_type();
    $data['query_parameters'] =  $this->view_single_test->query_parameters();
    $data['query_tech_name'] =  $this->view_single_test->query_tech_name();
    $data['query_test'] =  $this->view_single_test->query_test();
    $data['query_temperat'] =  $this->view_single_test->query_temperat();
    $data['query_semiq'] =  $this->view_single_test->query_semiq();
    $data['query_conclusion'] =  $this->view_single_test->query_conclusion();
    $data['query_side'] =  $this->view_single_test->query_side();

    $this->load->model('mysql_create','',true);
    $data['dropdown_conclusion_diagnosis'] = $this->mysql_create->get_dropdown_conclusion($tech_num);
    $data['dropdown_conclusion_duration'] = $this->mysql_create->get_dropdown_duration_diagnosis();
    $data['dropdown_conclusion_severity'] = $this->mysql_create->get_dropdown_severity_diagnosis();

    $this->load->view('auh/se_enkel_test', $data);
    }

View ->

elseif ($struct_id == "3") {

            foreach($query->result() as $rows):
            if ($rows->NerveCode > 10000 ){
                echo "<h3>N." . $rows->NerveName . ") (" . $side->SideText.")</h3>";        

            }
            else {
                echo "<h3>N." . $rows->NerveName . " (" . $rows->ProxName . " - ";
                    if ($rows->Code < 3000) {
                        echo "m.";
                        }
                    echo $rows->DistName . ") ("  . $side->SideText.")</h3>";
            }
            endforeach;
            $anatomic_code = $rows->NerveCode;
            $ProxAccess = $rows->ProxAccess;
            $DistAccess = $rows->DistAccess;
    }

This is how my page looks now facing the errors, one should be aware there several errors above this page, as stated earlier in the post. but the same two errors for all 3 variables.

This is how the original page used to look.

From the two screenshots you can see that the problem on my page is I'm not getting the "length of segment" value.. and the muscle name: "N.peroneus (ankle - m.extensor digitorum brevis) (sin.)"

The model with function "query" ->

function query()
{
    $exam = $this->uri->segment(3);    
    $type_id = $this->uri->segment(4);
    $struct_id = $this->uri->segment(5);    
    $technique_id = $this->uri->segment(6);
    $test_id = $this->uri->segment(7);
        switch($type_id)
        {
            case 1:
                $query_input = "SELECT EMUSCLE.*, NERVMUSCACCP.NAME AS MuscleName, NERVMUSCACCP.ShortName AS ShortMuscleName FROM EMUSCLE,NERVMUSCACCP WHERE Exam = ".$exam." AND Struct = ".$struct_id." AND EMUSCLE.MuscleCode = NERVMUSCACCP.Code;";
                break;
            case 2:
                $query_input = "SELECT ENERVE.*, NERVMUSCACCP.NAME AS NerveName, NERVMUSCACCP.ShortName AS ShortNerveName FROM ENERVE,NERVMUSCACCP WHERE Exam = ".$exam." AND Struct = ".$struct_id." AND ENERVE.NerveCode = NERVMUSCACCP.Code;";
                break;
            case 3:
                $query_input = "SELECT NewTable2.*, prox2.Code, prox2.Name AS DistName, prox2.ShortAccPName AS ShortDistName FROM (SELECT NewTable1.*, prox.Name AS ProxName, prox.ShortAccPName AS ShortProxName FROM (SELECT es.*,  NERVMUSCACCP.NAME AS NerveName, NERVMUSCACCP.ShortName AS ShortNerveName FROM ESEGMENT es, NERVMUSCACCP WHERE Exam = ".$exam." AND Struct = ".$struct_id." AND es.NerveCode = NERVMUSCACCP.Code) AS NewTable1 LEFT OUTER JOIN PROXDISTINFO prox ON NewTable1.ProxAccess = prox.Code) AS NewTable2 LEFT OUTER JOIN PROXDISTINFO prox2 ON NewTable2.DistAccess = prox2.Code;";
                break;
            case 4:
                $query_input = "SELECT NewTable1.*, NERVMUSCACCP.NAME AS MuscleName, NERVMUSCACCP.ShortName AS ShortMuscleName FROM (SELECT EJNCTION.*, NERVMUSCACCP.NAME AS NerveName, NERVMUSCACCP.ShortName AS ShortNerveName FROM EJNCTION LEFT OUTER JOIN NERVMUSCACCP ON EJNCTION.NerveCode = NERVMUSCACCP.Code WHERE EJNCTION.Exam = ".$exam." AND Struct = ".$struct_id.") AS NewTable1 LEFT OUTER JOIN NERVMUSCACCP ON NewTable1.MuscleCode = NERVMUSCACCP.Code";
                break;
        }    
    $query = $this->db->query($query_input);

    return $query;
}

It seems you are not actually passing the query result to the view:

$data['query'] = $this->view_single_test->query();

Without seeing the model it's hard to make an educated guess. The value assigned to $data['query'] should be the result object. Not the cleanest, but try this returning $query->result(); from the model and assign that to a variable in the controller which is then passed on to the view.