-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return from method Count() doesn't match with the actual rows #20
Comments
When I debug the code I found the raw SQL generated "SELECT COUNT(*) AS When I try it in the phpmyadmin, it return 497 rows. So the method count() is not wrong but the way to get the total rows of datatables in the bundle is not exactly correct by using count(). What do you think? :) |
Here is a final code of method count()
I have to reassign the selects again because after $copy_query->get(), laravel removes selects. Very weird. :p |
Using count($copy_query->get()); is not the optimized way :). We shouldn't use this to just get the count of all lines which query returns because it will use more memory and cpu. Group_by is working a little bit weird with count. Actually, I expect that when you tried in phpmyadmin, you saw lines more than one which has aggregate column for each group of group_by statement. Did you see anything like this? Besides can you share your normal query which returns lines to show at list. BTW, I guess, copy_query is not neccassary. I don't know, why I used it. But, it will work without it, too. Lastly, thanks for your investigation and interest 👍 |
Yes Bilal, you are absolutely right. I saw lines more than one with same number, 497. 497 |
Because you are using group by statement, you should use different sql structure to calculate count of lines like this:
(http://stackoverflow.com/questions/6709747/mysql-query-using-sum-of-count) I will update the code so that you can use your count function (even more) when you create your query. |
I see. Thank you for your help. :D Anyway, your name same like famous muadzin in history, bilal |
Yes it is :) . By the way, sorry for delay. I couldn't update the code because of exams and works. I hope, I will update soon :) . |
Hi, I found a bug when I use this bundle
I have a complex query
$products = Product::join($productlist_table,"$productlist_table.kodebrg",'=',"$product_table.kodebrg")
->where("$product_table.infobrosur", '=', 'Y')
->group_by("$product_table.kodebrg")
->select(array("$product_table.kodebrg",'namabrg', 'kdspek', "$harga_jual_column as hargajual"));
This query return 500 rows and works well. Then I search from datatables looking for text "ESIA" and it return 10 rows in table but the count return from the bundle is 497 rows not 10. So, the pagination shows wrong number.
Here is the bundle's function
So I solve the problem by changing method count() to get()
and now it runs. I don't know maybe someone else face same problem with me.
The text was updated successfully, but these errors were encountered: