Welcome Guest, Not a member yet? Register   Sign In
DataMapper - View does not match Query
#1

[eluser]Genki1[/eluser]
Hi WanWizard,

What is the recommended way to pass a query result to a view?

I'm not able to get the results I expect and would appreciate your insight. Here's what is happening:

In my controller, I perform a $obj->get() and the $obj->result_count() correctly indicates the expected number of matching records. Manually running the sql from $obj->check_last_query() in phpMyAdmin also displays the expected records. So far, so good.

Next, I pass that $obj to my view. Looping over the $obj, I get ALL the records in the table, not just the matching records I'm expecting. Why?

Example:

my_controller.php

Code:
$u = new User;
$u->where condition 1
$u->where condition 2
etc...
$u->get();
$u->result_count();      // correctly indicates 4 records found
$u->check_last_query();  // using this SQL in phpMyAdmin correctly displays the expected 4 records
// Pass the data to the view
$data['matching_records'] = $u;
$this->load->view('my_view', $data);

my_view.php

Code:
foreach ($matching_records as $record):
  echo $record->id;      // displays 19 records!
endforeach;

So, in the view, all the records are displayed, not the expected set of just 4 records found in my query.

What is the recommended way to pass the result set to the view and to loop over it?




Theme © iAndrew 2016 - Forum software by © MyBB