• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make the second $this->db->get() with one query instructions.

#1
[eluser]peekk[/eluser]
Hey I have the following problem:

I have a very long MySQL query, and then I want to count rows which it returns.

After getting this result I want to make it again with some limit and group my results by one of columns.

So it looks that:

Code:
/*
query conditions....
query conditions....
query conditions....
query conditions....
query conditions....
query conditions....
query conditions....
*/

//first query

$query = $this->db->get();

$results = $query->result_array();
            
$this->db->select("FOUND_ROWS() as cnt");
            
$cnt_array = $this->db->get()->row_array(); //here is my number of rows


//second query and if instruction


            if($sth==0) { $this->db->group_by(...);}
          

            $this->db->limit($count, $from);
  
            
            $query = $this->db->get();
            $results = $query->result_array();
  
            $this->db->select("FOUND_ROWS() as cnt");
            
            $tot_cnt = $this->db->get()->row_array(); //now i want to have number of grouped results.

but the second query doesnt work, how to do it?




#2
[eluser]Sanjay Sarvaiya[/eluser]
Have you tried
Code:
$this->db->last_query()

you can see what's wrong with your query.

use before second query
Code:
$query->free_result();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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