Get records count within query |
[eluser]nuwanda[/eluser]
If I create a query to return records can I also get a count of all records in the same query? Yes, I know CI has functions to get a count of all records but that requires a new query.
[eluser]Bart v B[/eluser]
something like this? Code: <?php
[eluser]Atharva[/eluser]
If you are talking about count query for pagination, then you will have to write a separate query.
[eluser]nuwanda[/eluser]
Yep, sure, sql will get records to the LIMIT clause then stop. That saves processing. I suspect this is an old problem.
[eluser]nuwanda[/eluser]
For clarity, this returns two records: Code: $query = ''; But if I add a count: Code: $query = ''; tags_count returns 2 as expected but the query outputs only one record. It's baffling. This is despite no LIMIT being involved.
[eluser]InsiteFX[/eluser]
And how are you returning the query? You need to show the rest of the code so we can help you. Also show your view code. InsiteFX
[eluser]Madmartigan1[/eluser]
Not for nothin, but phps built-in count() function should be all you need. Code: $rows = $this->db->where('something', $something)->get('my_table'); And as Atharva said: Quote:If you are talking about count query for pagination, then you will have to write a separate query. EDIT: Misread OP. No you can't count ALL records in the same query.
[eluser]InsiteFX[/eluser]
CodeIgniter User Guide - Generating Query Results Code: $count = $query->num_rows(); InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |