-2

I am having issues figuring out why my $data variable isn't passing to my search_view, I pass sql data from model as shown below:

        $this->db->like('LOWER(title)', strtolower($query));
        $q = $this->db->get('questions');
        $data = $q->row_array();
        $q->free_result();

        $this->load->view('search_view', $data);

and than try to echp out a row in my search_view for example echo $data['title']; however get an error saying that variable data is undefined.

I tested it and echoed same thing out without loading a view, just an echo from model works. So I am sure it is getting correct data from database.

tereško
  • 58,060
  • 25
  • 98
  • 150
Ilja
  • 44,142
  • 92
  • 275
  • 498

2 Answers2

1

The elements of the array you pass become variables in the view, It's

echo $title;

instead of

echo $data['title'];
Marcel Gwerder
  • 8,353
  • 5
  • 35
  • 60
0

try this

 $this->load->view('search_view', array('data'=>$data));

and in view file

 echo $data['title'];
Vipin Kumar KM
  • 356
  • 5
  • 17