[eluser]developer10[/eluser]
First of all, my query runs twice (once for counting, once for limiting and displaying data):
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;
}
But, what i want more than preventing the query run twice (i know many people here have the same problem),
is to move those pagination configs to my controller.
My question is: Is it possible to declare a variable like this:
Code:
$varToPass = $noLimit->num_rows();
and then pass it from the model to my controller (i want to use it there as total_rows config item for pagination)? That way i think i'd be able to move everything
related to pagination to the controller.
THANKS!