Search result error

#1
[eluser]novarli[/eluser]
I have scripts

Controller
Code:
function search(){
        if($this->account['role'] != 'admin'){
            show_error('You cannot access this page');    
            exit();
        }
        $data['head']['title'] = 'City - FirstLabor';

        $data['head']['style'] = '<link href="'.base_url().'css/form.css" rel="stylesheet" type="text/css" media="screen" />'."\n";

        $data['head']['script'] = '[removed][removed]'."\n";
        $data['head']['script'] .= '[removed]window.onload=focus_country[removed]'."\n";
        $data['tab'] = $this->config->item('tab');
        $data['account'] = $this->session->userdata('account');

        $data['page']['primary'] = 'Administration';
        $data['page']['secondary'] = 'File';
        $data['page']['title'] = 'CITY';
        $data['form']['action'] = 'city/search_res';
        $data['form']['submit'] = 'Search';

        $data['tab'] = $this->config->item('tab');
        $data['account'] = $this->session->userdata('account');    
        $data['province'] = $this->cities->getProvince();    
        $rules['txtName'] = 'required';        
        $this->load->view('city/search', $data);
        
    }
    
    function search_res(){
    $data['head']['title'] = 'City - FirstLabor';

    $data['head']['style'] = '<link href="'.base_url().'js/jquery/tablesorter/themes/blue/style.css" rel="stylesheet" type="text/css" media="screen" />';

    $data['head']['script'] = '[removed][removed]'."\n";
    $data['head']['script'] .= '[removed][removed]'."\n";

    $data['page']['primary'] = 'Administration';
    $data['page']['secondary'] = 'File';
    $data['page']['title'] = 'CITY';
    $data['tab'] = $this->config->item('tab');
    $data['account'] = $this->account;
    $config['base_url'] = base_url().'city/search_res';
    
    $txtName=$this->input->post('txtName');
    $province=$this->input->post('province');    
    $data['count_result'] = $this->cities->count_result($txtName,$province);
    $config['total_rows'] = $data['count_result'];
    $config['per_page'] = 10;
    $this->pagination->initialize($config);
    $offset = $this->uri->segment(3);
    $data['search_res'] = $this->cities->getSearchResult($txtName,$province, $config['per_page'], $offset);
    
    $this->load->view('city/search_res', $data);
    
    }

Model
Code:
function getSearchResult($city,$province,$limit,$offset){
    $this->db->select('cities.id,cities.name as city_name,provinces.name as province_name');
    $this->db->from('cities');
    $this->db->join('provinces','cities.province = provinces.id');
        if (!empty($city))
        {
            $this->db->like('cities.name',$city);
        }
        
        if ($offset)
        {
            $this->db->limit($limit,$offset);        
        }
        else
        {
            $this->db->limit($limit);        
        }
        if ($province!=0){
         $this->db->where('province', $province);
        }
    $this->db->order_by('cities.name');
    return $this->db->get();    
    }
    
    function count_result($city,$province)
    {
    $this->db->select('cities.id,cities.name as city_name,provinces.name as province_name');
    $this->db->from('cities');
    $this->db->join('provinces','cities.province = provinces.id');
        if (!empty($city))
        {
            $this->db->like('cities.name',$city);
        }
        if ($province!=0){
         $this->db->where('province', $province);
        }
    return $this->db->get();        
    }

and view (search_res.php)
Code:
<? foreach ($search_res as $p): ?>
        &lt;?php echo $p->city_name; ?&gt;<br>
        &lt;? endforeach; ?&gt;
Error appears

Severity: Notice

Message: Trying to get property of non-object

Filename: city/search_res.php

Line Number: 24

Code:
&lt;?php echo $p->city_name; ?&gt;<br>

What happen?
[/code]


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.