We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Offset and count()

Developer Preview

Reinos's avatar
Reinos
79 posts
7 years ago
Reinos's avatar Reinos

Hi Guys,

I have a weird issue. it seems that count() always return zero when using ->offset().

ee('Model')->get('ChannelEntry')->offset(10)->count(); //return 0
ee('Model')->get('ChannelEntry')->count(); //return correct number

It seems like an issue with MySQL and not with EE self (https://stackoverflow.com/questions/32814423/mysql-get-count-of-items-after-offset). But it would be nice to fix this.

Any idea how to get around this problem?

       
Derek Jones's avatar
Derek Jones
7,561 posts
7 years ago
Derek Jones's avatar Derek Jones

I’d probably do something similar to the suggestions there, and keep your logic in PHP if you want. Number of ways to handle it, one might be:

$offset = 10;
$total = ee('Model')->get('ChannelEntry')->count();
$count = ($total - $offset > 0) ? $total - $offset : 0;
       
Reinos's avatar
Reinos
79 posts
7 years ago
Reinos's avatar Reinos

Of course… Thanks!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.