I'm having some problem with this script... works fine, but not for the total of records found on the query.
I have this function on my ORM called "mix". There are 3 tables: mixes, generos and mixes_generos.
I can search in the table "mixes" or on the table "generos", anyone.
public function search($query, $itemsperpage, $page)
{
if (empty($page))
$page = 1;
$offset = ($page - 1) * $itemsperpage;
$orm = $this->join('mixes_generos', 'LEFT')->on('mix.id', '=', 'mixes_generos.mix_id')
->join('generos', 'LEFT')->on('generos.id', '=', 'mixes_generos.genero_id')
->where_open()
->or_where('mix.nombre', 'LIKE', '%'.$query.'%')
->or_where('mix.descripcion', 'LIKE', '%'.$query.'%')
->or_where('generos.nombre', 'LIKE', '%'.$query.'%')
->where_close()
->and_where('mix.estatus', '=', 'active')
->order_by('mix.fecha_produccion', 'DESC')
->order_by('mix.track', 'DESC');
$this->_search_total = $orm->reset(FALSE)->count_all();
$orm = $orm->limit($itemsperpage)->offset($offset);
return $orm;
}
public function search_total()
{
return $this->_search_total;
}
Then, in my controller i have this:
$data = ORM::factory('mix')->search('pop music', 10, 1);
if I want to echo the total, i do this:
echo $data->search_total();
in my view I print the info:
foreach($data->find_all() as $mix)
echo $mix->nombre;
http://s10.postimage.org/cvnr28nop/records.jpg
in this link you will see the result, look closely the column "records_founds" vs the number of "records" that it founds, 3 vs 1??.
And that is the main problem... because when i print the data of the mixes shows 3 instead 1. I also add an group_by('mix.id') and nothing :(
What do you think?
Thank you