CodeIgniter Forums
Active Records help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Active Records help (/showthread.php?tid=41584)



Active Records help - El Forum - 05-11-2011

[eluser]Miguel Diaz[/eluser]
Hi I dont understan to much about active records and I have a situation trying to load the library pagination and add it to my database query.

This is my database model function
Code:
function mostrarLocatarios($delegacion,$colonia,$ciudad)
    {
        $cad_busqueda="";
        
        if( !empty($delegacion) )
            $cad_busqueda="AND c.categoriaNombre='$delegacion' ";
            
        if( !empty($colonia) )
            $cad_busqueda.="AND s.subCategoria='$colonia' ";
        
        if( !empty($ciudad) )
            $cad_busqueda.="AND l.localCiudad='$ciudad' ";
        
            $query = $this->db->query("select
                                    l.localId as 'localId',
                                    l.localID as 'localID',
                                    l.localDuenio as 'localDuenio',
                                    l.localLogo as 'localLogo',
                                    l.localNumero as 'localNumero',
                                    l.anuncioPagado as 'pagado',
                                    ls.subCategoriaID as 'subcategoriaID',
                                    l.listaOrden as 'listaOrden',
                                    c.categoriaNombre as 'categoriaNombre',
                                    l.localCiudad as 'localCiudad',
                                    GROUP_CONCAT(DISTINCT CONCAT('<a >', s.subCategoria, '</a>')) as subCategoria,
                                    l.localNombre as 'localNombre',
                                    sum(lc.rate)  / count(lc.calificacionID) as Calificacion
                                    FROM locatarios l
                                    left join locatarioCalificacion lc on (l.localID = lc.localID)
                                    left join locatariosSubcategorias ls on (ls.locatarioID = l.localID)
                                    left join categorias c on(c.categoriaID = l.categoriaID)
                                    left join subcategorias s on (s.subcategoriaID = ls.subcategoriaID)
                                    where l.categoriaID=c.categoriaID  $cad_busqueda
                                    group by l.localID
                                    order by l.anuncioPagado asc, l.listaOrden asc
                                    ");
        if( $query->num_rows()>0 )
            return $query->result();
        else
            return -1;
    }

Code:
and I dont know how to add the variable $config per page in my above query

$this->db->order_by('localID', 'DESC');
        $op['locatarios'] = $this->db->get('locatarios', $config['per_page'], $this->uri->segment(3));

I hope someone can help me please.
Thanks in advance


Active Records help - El Forum - 05-11-2011

[eluser]cideveloper[/eluser]
you have to pass those values from the controller to the model


Active Records help - El Forum - 05-11-2011

[eluser]Miguel Diaz[/eluser]
Thanks for your reply can you put me an example how to pass it please


Active Records help - El Forum - 05-12-2011

[eluser]InsiteFX[/eluser]
What ever happened to normalizing a database?

InsiteFX