Welcome Guest, Not a member yet? Register   Sign In
Returning number of rows
#1

[eluser]alvaroeesti[/eluser]

Hello

Well, I need two pieces of information. One the block of rows with their content, and the other how many rows they are, for pagination purposes.


UPDATED:


I solved it by some weird way, (if anyone has a better idea, I ll be interested in hearing about it). I solved this way. I realized that I had two objects, which were being returned as an array of objects. So in order to return all that at once I created an array of arrays of objects. Once at the controller, I unshifted them of the multidimensional array and I used one for returning the content and the other one to get the number of rows by nothing else than counting (using count) the number of items the array had.

=====

continuing with old post:

I do my first query which goes like this:

Code:
$this->db->select('id_atributo, thumb_a,etc');
  
  $this->db->from('localidades x');
  $this->db->join('regiones y', 'y.id_region = x.id_region');
                etc

$this->db->limit(2, 0);
  
  $query = $this->db->get();

And then I sort of repeat the same query except for the Limit stuff, and add this to get the number of rows:

Code:
$question = $this->db->get();
  
  
$filas = $question->num_rows();


So, now that I have these two queries within one Function in the model, I need to return all that:

Code:
return $query->result();

But as you see, I only know how to return the first query. I don't know how to add the additional piece of info, which is the total number of rows that I do in the second query.

You might ask yourself why I repeat the queries. The thing is that if I do num_rows when I have used the Limit, it does not bring me the total number of rows but just the ones chunked by the Limit clause. That is why I repeat the query again without the Limit.

In the controller I have this:


Code:
$data = $this->toModelPage->toModelFunction($etc);

So, that is the issue, how to pass the number of Rows. I have got it fine when it is just about passing the array of objects, but the problem is that additional num_rows() stuff.


thank you

regards

A


Messages In This Thread
Returning number of rows - by El Forum - 10-14-2012, 07:00 AM
Returning number of rows - by El Forum - 10-14-2012, 08:30 AM
Returning number of rows - by El Forum - 10-14-2012, 08:37 AM
Returning number of rows - by El Forum - 10-14-2012, 08:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB