CodeIgniter Forums
Can I: get() and count_all_results() within the same $this->db - 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: Can I: get() and count_all_results() within the same $this->db (/showthread.php?tid=11081)



Can I: get() and count_all_results() within the same $this->db - El Forum - 08-25-2008

[eluser]Matrices[/eluser]
Here's my code:

Code:
$this->db->where('username', $_POST['username']);
$this->db->where('password', $_POST['password']);
$query = $this->db->get('accounts');
$rows = $this->db->count_all_results('accounts');

I'm running into a problem where the $rows counted are ALL the rows from the database, which means the filter is only working for the first query, in the 3rd row. Is there a way that I can use the filter created within the first two lines to work for more than just the first query line? Or do I have to reintroduce the filter for the second query?


Can I: get() and count_all_results() within the same $this->db - El Forum - 08-25-2008

[eluser]Pascal Kriete[/eluser]
All forms of get(), as well as count_all_results() reset the query, but you can use $query->num_rows() to get the row total for a query.


Can I: get() and count_all_results() within the same $this->db - El Forum - 08-25-2008

[eluser]Matrices[/eluser]
Ah, ty. That's perfect


Can I: get() and count_all_results() within the same $this->db - El Forum - 10-20-2008

[eluser]koorb[/eluser]
I am trying to page results, I have built up quite a complicated set of dynamic criteria to search the db on, I want the limited results and the total number of records that match the criteria. Is this possible? $query->num_rows() will only give me the number returned with limits.

TIA