problem in calculating count |
[eluser]Bigil Michael[/eluser]
i want to count the no: of distinct items in table i used query like this Code: function get_total() can any one help me thanks in advance....
[eluser]danmontgomery[/eluser]
Code: function get_total() {
[eluser]InsiteFX[/eluser]
Code: $this->db->select('COUNT("id") AS total'); InsiteFX
[eluser]d1a8lo24[/eluser]
Try this. Code: function get_total() OK now I remember i found one of my old applications, your not getting a wrong total what you're doing is counting the amount of cities in each group, because of the distinct function. So if you do a var_dump youll have something like New York -> 10 Los Angeles -> 5 San Francisco -> 7 so your code is actually doing what it suppose to but because of the group by your getting this. So you can try the code at the beginning but here is the question what total do you want? The total of unique cities. The total of all cities including duplicates. The code above may give you the total of unique cities. You can also return the array instead of just one row and use the php count() function on the array that will give you a total of the unique cities. Last if you want everything including duplicates then you do count_all() function from CI. More info here. http://ellislab.com/codeigniter/user-gui...lpers.html
|
Welcome Guest, Not a member yet? Register Sign In |