• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination for complex query

#11
[eluser]BrainCatcher[/eluser]
hmmm,

The count works but i'm only getting 1 row returned from the query...

weird, llookin for another solution..

#12
[eluser]developer10[/eluser]
I have the same problem (queries are run twice):

Code:
0.0687       SELECT * FROM _tbl_firme LEFT JOIN tbl_djelatnosti ON _tbl_firme.d_id = tbl_djelatnosti.d_id WHERE  d_seo = 'informatika-elektronika-racunari-i-oprema' AND  _f_grad = 'Sarajevo' AND  f_vidljivo = 1 ORDER BY f_istaknuto DESC, _f_ime ASC  
0.0390       SELECT * FROM _tbl_firme LEFT JOIN tbl_djelatnosti ON _tbl_firme.d_id = tbl_djelatnosti.d_id WHERE  d_seo = 'informatika-elektronika-racunari-i-oprema' AND  _f_grad = 'Sarajevo' AND  f_vidljivo = 1 ORDER BY f_istaknuto DESC, _f_ime ASC LIMIT 0, 10

This is my model method:

Code:
function fetch_all($getDjelatnost, $getGrad, $getSlovo, $getStart, $per_page)
    {    
        $qry = " SELECT * FROM _tbl_firme LEFT JOIN tbl_djelatnosti ON _tbl_firme.d_id = tbl_djelatnosti.d_id WHERE ";
            if($getDjelatnost && $getDjelatnost != 'Sve')
                $append = " d_seo = '$getDjelatnost' AND ";
            else $append = "";
                $qry .= $append;
                
            if($getGrad && $getGrad != 'Svi')
                $append = " _f_grad = '$getGrad' AND ";
            else $append = "";
                $qry .= $append;
                
            if($getSlovo)
                $append = " _f_ime LIKE '$getSlovo%' AND ";
            else $append = "";
                $qry .= $append;
                
            if($getFid)
                $append = " f_id = '$getFid' AND ";
            else $append = "";
                $qry .= $append;
                
            if($getPortfolio)
                $append = " _F_KEYWORD = '$getPortfolio' AND ";
            else $append = "";
                $qry .= $append;
                        
        $qry .= " f_vidljivo = 1 ORDER BY f_istaknuto DESC, _f_ime ASC ";
                

        $limited = $qry . "LIMIT ";
            if($getStart)
                $append = $getStart;
            else $append = 0;
                $limited .= $append;
                
        $limited .= ", " . $per_page;
            
        
        $noLimit =            $this->db->query($qry);
        $withLimit =        $this->db->query($limited);
            
            //// pagination config
            $pagBase = site_url() . 'prikazi/adresar/';
                if($getDjelatnost) $add = "djelatnost/{$getDjelatnost}/"; else $add=""; $pagBase .= $add;
                if($getGrad) $add = "grad/{$getGrad}/"; else $add=""; $pagBase .= $add;
                if($getSlovo) $add = "slovo/{$getSlovo}/"; else $add=""; $pagBase .= $add;
            $pagBase .= "start";

            $config['num_links'] = 4;
            $config['uri_segment'] = $this->uri->total_segments();
            $config['base_url'] = $pagBase;
            $config['total_rows'] = $noLimit->num_rows(); //$this->db->count_all_results();
            
            $this->pagination->initialize($config);
            ////////////////
        
        if($withLimit->num_rows() > 0) {
            $result = $withLimit->result();
        }
        
        return $result;
    }

Maybe I could forget duplicate running of queries, IF i am able to get rid of these config items in my model (move them to controller instead)
so, is there any way that i can:

Code:
$varToPass = $noLimit->num_rows();

pass from the model to my controller?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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