|
|||
|
I'm building a pagination, but I have a question in my mind
php count() and count(*) in mysql would be better if the data size is getting bigger? Or do you have other efficient way to get the "number of elements" in a collection and the data all together?? Because if I use sql way, I need to send 2 queries to database.... Last edited by iroy2000 : 03-21-2008 at 03:38 PM. |
|
||||
|
MySQL count is probably faster, but not on star. Do it on your primary key field, and it should be faster.
Also, don't call either again and again - set the result to a variable and reference that. Especially in a loop.
__________________
- xentek |
|
|||
|
If you make php count, this does mean that you have to retrieve all the records ... and query one more time for results depending on current page, therefore it php count is slower.
If you have 100 k records you'll feel the difference. Slavi |
|
|||
|
Keep in mind this is only safe if the field you're counting on is 'not null'. Counting on fields skips null values.
|
|
||||
|
Indeed. I should have noted that. I usually count on my primary key, which by design does not hold any null values.
__________________
- xentek |
![]() |
| Thread Tools | |
| Display Modes | |
|
|